-
Notifications
You must be signed in to change notification settings - Fork 192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add 'verdi node repo dump' command. #3623
Changes from 20 commits
f743114
44413d8
6bd8b2a
2c18ba0
27ed482
b63281e
e616d7e
29ece24
ddf3048
8829b46
d9ff8ac
da7ab3f
445880a
023583b
f32d03c
290d5ac
340fa3e
39f0800
00e0d63
10a9583
7e60feb
ef4a659
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,9 @@ | |
########################################################################### | ||
"""`verdi node` command.""" | ||
|
||
import shutil | ||
import pathlib | ||
|
||
import click | ||
import tabulate | ||
|
||
|
@@ -61,6 +64,52 @@ def repo_ls(node, relative_path, color): | |
echo.echo_critical(exception) | ||
|
||
|
||
@verdi_node_repo.command('dump') | ||
@arguments.NODE() | ||
@click.argument( | ||
'output_directory', | ||
type=click.Path(), | ||
required=True, | ||
) | ||
@with_dbenv() | ||
def repo_dump(node, output_directory): | ||
"""Copy the repository files of a node to an output directory.""" | ||
from aiida.orm.utils.repository import FileType | ||
|
||
output_directory = pathlib.Path(output_directory) | ||
|
||
try: | ||
output_directory.mkdir(parents=True, exist_ok=False) | ||
except FileExistsError: | ||
click.echo('Error: Invalid value for "OUTPUT_DIRECTORY": Path "{}" exists.'.format(output_directory)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
raise click.Abort | ||
|
||
def _copy_tree(key, output_dir): # pylint: disable=too-many-branches | ||
ltalirz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
""" | ||
Recursively copy the content at the ``key`` path in the given node to | ||
the ``output_dir``. | ||
""" | ||
for file in node.list_objects(key=key): | ||
# Not using os.path.join here, because this is the "path" | ||
# in the AiiDA node, not an actual OS - level path. | ||
file_key = file.name if not key else key + '/' + file.name | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a good point and I now start to wonder whether we actually handle this correctly and consistently everywhere in the repositiory interface. Anyhow, this is good for now. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Well, that's only going to be a problem if |
||
if file.type == FileType.DIRECTORY: | ||
new_out_dir = output_dir / file.name | ||
assert not new_out_dir.exists() | ||
new_out_dir.mkdir() | ||
_copy_tree(key=file_key, output_dir=new_out_dir) | ||
|
||
else: | ||
assert file.type == FileType.FILE | ||
out_file_path = output_dir / file.name | ||
assert not out_file_path.exists() | ||
with node.open(file_key, 'rb') as in_file: | ||
with out_file_path.open('wb') as out_file: | ||
shutil.copyfileobj(in_file, out_file) | ||
|
||
_copy_tree(key='', output_dir=output_directory) | ||
|
||
|
||
@verdi_node.command('label') | ||
@arguments.NODES() | ||
@options.LABEL(help='Set LABEL as the new label for all NODES') | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you write a note saying that the output directory should not exist
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done! I did notice though that this doesn't appear anywhere in the documentation, only the top-level command help is shown. That should probably be improved, we could show the help for all command groups.