-
Notifications
You must be signed in to change notification settings - Fork 191
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
Conversation
The command takes a node pk / uuid, zero or more file names, and an ouput directory as arguments. By default, it will create a sub-directory with the node uuid in the output directory, and copy the files with the given names from the repository to that directory. If no file names are given, all objects in the repository are copied. The command has two optional flags: --no-uuid: copies the files directly into the output directory, without uuid prefix --force: Copy files even if they already exist at the target destination
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.
Probably this misses proper dealing with folders
The command is renamed to 'verdi node repo dump'. The option of specifying specific file names to be copied is removed. The output paths no longer prefixed with a UUID. When a file or directory exists already, the command prompts to either abort, skip the current file / directory, overwrite the file / directory, or (in the case of directories only) merge the contents. A 'force' option can be given to always overwrite files / directories. Tests are not yet updated to the changed interface, since we want to get feedback on that first.
Following the feedback session, made the following changes:
Current click help:
|
Mentioning @giovannipizzi @ltalirz for feedback. |
The described behaviour looks fine to me thanks! |
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.
thanks @greschd
I tried it out locally - some suggestions on the wording to make the prompts less long
Since there was quite some discussion, maybe we should show the updated interface again? |
2626e56
to
71f1b26
Compare
Apply suggestions for simplified wording of the prompts that ask if a file / directory should be replaced / merged / skipped, or the operation should be aborted. Co-Authored-By: Leopold Talirz <[email protected]>
71f1b26
to
6bd8b2a
Compare
Sure, we can do it briefly this evening. I think the others will approve. |
The command takes a node pk / uuid, zero or more file names, and an ouput directory as arguments. By default, it will create a sub-directory with the node uuid in the output directory, and copy the files with the given names from the repository to that directory. If no file names are given, all objects in the repository are copied. The command has two optional flags: --no-uuid: copies the files directly into the output directory, without uuid prefix --force: Copy files even if they already exist at the target destination
The command is renamed to 'verdi node repo dump'. The option of specifying specific file names to be copied is removed. The output paths no longer prefixed with a UUID. When a file or directory exists already, the command prompts to either abort, skip the current file / directory, overwrite the file / directory, or (in the case of directories only) merge the contents. A 'force' option can be given to always overwrite files / directories. Tests are not yet updated to the changed interface, since we want to get feedback on that first.
Apply suggestions for simplified wording of the prompts that ask if a file / directory should be replaced / merged / skipped, or the operation should be aborted. Co-Authored-By: Leopold Talirz <[email protected]>
…ore into add_node_repo_cp_command
e71a17e
to
8829b46
Compare
The code was currently broken because not all flags were changed from 'o' to 'r' (in the rename from 'overwrite' to 'replace'). Adds a test which runs with '--force' where a single file is replaced.
When passing a pathlib.Path to 'shutil', it needs to be explicitly cast to 'str'. The compatibility of 'os' and 'shutil' with pathlib objects was added only in Python 3.6.
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.
thanks a lot @greschd
to me this looks ready to be merged
@giovannipizzi, do you want to have a final look? |
I did not, but I would be ok with removing the "merge" option and only leave abort / skip / overwrite. |
Sorry, I did not take this up yet with @greschd . Apologies for coming with this after you have already implemented it but I was wondering if it is not a simpler/safer to make the target directory into which the files should be dumped a required argument and require that it cannot exist. If the goal of the command is to be as simple as possible and just dump the entire content of a node's repo this seems in line with that goal. I think for the same reason we decided not to provide flags to include/exclude certain paths. @ltalirz pointed out that it prevents one from dumping in the current directory, but my argument would be that doing |
So the proposed syntax would be
which means the user wouldn't have to
No worries, I'm not particularly attached to my code - that also doesn't make a particularly strong technical argument 😄 I'm fine with making this as simple as possible. |
I think it is fine to automatically create a nested folder, as long as the leaf folder does not already exist. This is just to prevent copying files by accident into an already existing folder. So interface:
with But before we go ahead, lets get an OK on this proposal from @giovannipizzi and @ltalirz and yourself :) |
Good for me. The |
I would not have created intermediate paths, but I do not see a major problem with this, so I'm ok with Sebastiaan's proposal. |
…o add_node_repo_cp_command
Yes, that's the intended behavior. In principle this could be handled by
is not very clear IMO, so I'll instead handle it directly and write
|
Instead of prompting when a file / directory exists, we now only allow specifying an OUTPUT_DIRECTORY that does not exist, and simply abort the command if it does.
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.
thanks @greschd , looks good to me!
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.
Two minor final changes and then its good to go, I promise :)
aiida/cmdline/commands/cmd_node.py
Outdated
) | ||
@with_dbenv() | ||
def repo_dump(node, output_directory): | ||
"""Copy the repository files of a node to an output directory.""" |
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.
aiida/cmdline/commands/cmd_node.py
Outdated
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 comment
The reason will be displayed to describe this comment to others. Learn more.
can you please use aiida.cmdline.utils.echo.echo_critical
here
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!
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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
Well, that's only going to be a problem if os.sep
is a backslash.. not the trickiest part for Windows support, I suppose 😄
Add a note that the output directory should not exist to the doc- string. When it does, abort with the 'echo_critical' provided by AiiDA instead of the click default.
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.
Thanks a lot @greschd and especially for your patience
Fixes #1121.
The command takes a node pk / uuid, zero or more file names, and an output directory as arguments. By default, it will create a sub-directory with the node uuid in the output directory, and copy the files with the given names from the repository to that directory. If no file names are given, all objects in the repository are copied.
The command has two optional flags:
--no-uuid
: copies the files directly into the output directory, withoutuuid prefix
--force
: Copy files even if they already exist at the target destinationChanged from the discussion with @ltalirz: For specifying the source file names, I am now not using a separate flag, since that mimics how regular
cp
works. For example:Click help: