-
Notifications
You must be signed in to change notification settings - Fork 116
Fix backup numbering when .tar.gz files are decompressed to .tar #404
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
Changes from 2 commits
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 |
|---|---|---|
|
|
@@ -20,7 +20,19 @@ def backup(filenames, prefix="error", directory="./") -> None: | |
| series of error.1.tar.gz, error.2.tar.gz, ... will be generated. | ||
| directory (str): directory where the files exist | ||
| """ | ||
| num = max([0] + [int(file.split(".")[-3]) for file in glob(os.path.join(directory, f"{prefix}.*.tar.gz"))]) | ||
| backup_files = glob(os.path.join(directory, f"{prefix}.*.tar.gz")) + glob( | ||
| os.path.join(directory, f"{prefix}.*.tar") | ||
| ) | ||
| nums = [] | ||
|
Member
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. nums = [0] |
||
| for file in backup_files: | ||
| try: | ||
| if file.endswith(".tar.gz"): | ||
| nums.append(int(file.split(".")[-3])) | ||
| elif file.endswith(".tar"): | ||
| nums.append(int(file.split(".")[-2])) | ||
| except (ValueError, IndexError): | ||
| continue | ||
| num = max([0, *nums]) | ||
|
Member
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 just needs to be
Contributor
Author
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. Thanks for the suggestions. I have introduced the changes. |
||
| prefix = f"{prefix}.{num + 1}" | ||
| filename = os.path.join(directory, f"{prefix}.tar.gz") | ||
| logging.info(f"Backing up run to {filename}.") | ||
|
|
||
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.
I think this can be done as a single glob.
glob(os.path.join(directory, f"{prefix}.*.tar*")). There is no need to add two globs.