-
Notifications
You must be signed in to change notification settings - Fork 8
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
Improve force overwriting for existing output files #48
Conversation
Move the code logics to the front-level trexio_run script + minor cleanup
src/trexio_tools/trexio_run.py
Outdated
def remove_trexio_file(filename:str, overwrite:bool) -> None: | ||
"""Remove the TREXIO file/directory if it exists.""" | ||
if os.path.exists(filename): | ||
if overwrite: | ||
if '*' in filename: | ||
raise ValueError(f'TREXIO filename {filename} contains * symbol. Are you sure?') | ||
os.system(f'rm -rf -- {filename} ') | ||
else: | ||
raise Exception(f'Output file {filename} already exists but overwrite option is not provided. Consider using the `-w` CLI argument.') | ||
|
||
return | ||
|
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.
Suppose that a user calls trexio_convert -w $HOME/$MY_TREXIO_FILE
, this wil call rm -rf -- $HOME/$MY_TREXIO_FILE
. If the user made a mistake in his/her script and forgot to define $MY_TREXIO_FILE
, it wil make rm -rf $HOME/
. :-(
It would be safer to try to open the trexio file first and check something inside it like the trexio metadata, so that we are sure that the thing we remove is indeed a trexio file.
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, please have a look.
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.
Great! But there is a little danger with rm -rf
. See my comment on the source file.
Great idea! Will do that. |
Mainly moved the file removal logic to the high-level
trexio_run.py
script and fixed some inconsistencies. Now it callsrm -rf
so it should work for both TEXT and HDF5 back ends unlike the previous version that was printing an error message for TEXT TREXIO files.