Skip to content

Commit 08d3137

Browse files
committed
wip
1 parent 4fdd186 commit 08d3137

File tree

2 files changed

+36
-4
lines changed

2 files changed

+36
-4
lines changed

src/aiida/cmdline/commands/cmd_archive.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,10 @@ def inspect(ctx, archive, version, meta_data, database):
136136
help='Determine entities to export, but do not create the archive. Deprecated, please use `--dry-run` instead.',
137137
)
138138
@options.DRY_RUN(help='Determine entities to export, but do not create the archive.')
139+
@click.option(
140+
'--base-tmp-dir',
141+
help='Determine entities to export, but do not create the archive. Deprecated, please use `--dry-run` instead.',
142+
)
139143
@decorators.with_dbenv()
140144
def create(
141145
output_file,
@@ -158,6 +162,7 @@ def create(
158162
batch_size,
159163
test_run,
160164
dry_run,
165+
temp_dir
161166
):
162167
"""Create an archive from all or part of a profiles's data.
163168
@@ -209,6 +214,7 @@ def create(
209214
'compression': compress,
210215
'batch_size': batch_size,
211216
'test_run': dry_run,
217+
'temp_dir': temp_dir
212218
}
213219

214220
if AIIDA_LOGGER.level <= logging.REPORT:

src/aiida/tools/archive/create.py

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def create_archive(
5959
compression: int = 6,
6060
test_run: bool = False,
6161
backend: Optional[StorageBackend] = None,
62+
temp_dir: Optional[Union[str, Path]] = None,
6263
**traversal_rules: bool,
6364
) -> Path:
6465
"""Export AiiDA data to an archive file.
@@ -139,6 +140,12 @@ def create_archive(
139140
140141
:param backend: the backend to export from. If not specified, the default backend is used.
141142
143+
:param temp_dir: Directory to use for temporary files during archive creation.
144+
If not specified, a temporary directory will be created in the same directory as the output file
145+
with a '.aiida-export-' prefix. This parameter is useful when the output directory has limited
146+
space or when you want to use a specific filesystem (e.g., faster storage) for temporary operations.
147+
The directory must exist and be writable.
148+
142149
:param traversal_rules: graph traversal rules. See :const:`aiida.common.links.GraphTraversalRules`
143150
what rule names are toggleable and what the defaults are.
144151
@@ -179,6 +186,25 @@ def querybuilder():
179186
name: traversal_rules.get(name, rule.default) for name, rule in GraphTraversalRules.EXPORT.value.items()
180187
}
181188

189+
# Handle temporary directory configuration
190+
if temp_dir is not None:
191+
temp_dir = Path(temp_dir)
192+
if not temp_dir.exists():
193+
msg = f"Specified temporary directory '{temp_dir}' does not exist"
194+
raise ArchiveExportError(msg)
195+
if not temp_dir.is_dir():
196+
msg = f"Specified temporary directory '{temp_dir}' is not a directory"
197+
raise ArchiveExportError(msg)
198+
# Check if directory is writable
199+
if not temp_dir.is_writable():
200+
msg = f"Specified temporary directory '{temp_dir}' is not writable"
201+
raise ArchiveExportError()
202+
tmp_prefix = None # Use default tempfile prefix
203+
else:
204+
# Create temporary directory in the same folder as the output file
205+
temp_dir = filename.parent
206+
tmp_prefix = '.aiida-export-'
207+
182208
initial_summary = get_init_summary(
183209
archive_version=archive_format.latest_version,
184210
outfile=filename,
@@ -283,10 +309,10 @@ def querybuilder():
283309
# Create and open the archive for writing.
284310
# We create in a temp dir then move to final place at end,
285311
# so that the user cannot end up with a half written archive on errors
286-
import ipdb; ipdb.set_trace()
287-
base_temp_dir = '/mount' # or whatever directory you want to use
288-
with tempfile.TemporaryDirectory(dir=base_temp_dir) as tmpdir:
289-
# with tempfile.TemporaryDirectory() as tmpdir:
312+
# import ipdb; ipdb.set_trace()
313+
temp_dir = Path('/mount') # or whatever directory you want to use
314+
with tempfile.TemporaryDirectory(dir=temp_dir, prefix=tmp_prefix) as tmpdir:
315+
# NOTE: Add the `tmp_prefix` to the directory or file?
290316
tmp_filename = Path(tmpdir) / 'export.zip'
291317
with archive_format.open(tmp_filename, mode='x', compression=compression) as writer:
292318
# add metadata

0 commit comments

Comments
 (0)