-
Notifications
You must be signed in to change notification settings - Fork 250
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 remove backup dir functionality #101
Add remove backup dir functionality #101
Conversation
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 work, @neequole. We can get this feature merged in after a few minor changes. See the comments below.
shallow_backup.py
Outdated
@@ -657,6 +657,13 @@ def prompt_for_path_update(config): | |||
move_git_folder_to_path(current_path, abs_path) | |||
|
|||
|
|||
def clean_backup_dir(backup_path): |
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 add a docstring?
shallow_backup.py
Outdated
def clean_backup_dir(backup_path): | ||
try: | ||
shutil.rmtree(backup_path) | ||
print("{} Deleted backup directory {} {}".format(Fore.BLUE, backup_path, Style.RESET_ALL)) |
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.
- We should use
Fore.RED
andStyle.BRIGHT
here since removal is a "dangerous" action. - I usually put print statements before the action, and use the infinitive tense. "Deleting" and then I finish the line with ellipsis.
shallow_backup.py
Outdated
@@ -689,6 +697,13 @@ def cli(complete, dotfiles, configs, packages, fonts, old_path, new_path, remote | |||
print(Fore.RED + Style.BRIGHT + | |||
"Removed config file..." + Style.RESET_ALL) | |||
sys.exit() | |||
elif clean: | |||
backup_home_path = get_config()["backup_path"] | |||
if prompt_yes_no("Erase backup directory {}?".format(backup_home_path), Fore.RED): |
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've gone back and forth about actually prompting here. If we get to this point in the program, the user either used the -destroy_backup
flag, or hit "Destroy backup" in the menu. That's a pretty deliberate action.
I'm not entirely sure we need to prompt here. What are your thoughts?
Side thoughts
- Let's change the flag to
-destroy_backup
since that's a lot clearer. - Then we should refactor the other method names as needed.
- Let's add this option to the menu.
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.
@alichtman Do you mean removing the prompt and just go straightly on the delete operation? My thought was that for any dangerous action, we have to double confirm it to user that is why I added the prompt. Final thoughts?
For your side thoughts no. 3, do you mean adding it after this?
elif selection == "reinstall configs":
reinstall_config_files(configs_path)
# Add here
elif selection == "Destroy backups":
destroy_backup()
# Can you advise if we need to exit at this point or we can go on the git stuffs below?
sys.exit()
git_add_all_commit(repo, backup_home_path)
git_push_if_possible(repo)
sys.exit()
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.
My thought was that for any dangerous action, we have to double confirm it to user that is why I added the prompt.
Alright, I have a good solution. We only prompt if they select to remove the backup from the CLI. If they remove with the flag, do that without a double confirmation. So, the process will be slightly different based on how the user selects to remove the backup.
For your side thoughts no. 3, do you mean adding it after this?
I meant that we should add it to the menu of options people can choose from in the CLI.
* Rename clean flag to destroy_backup * Rename method clean_backup_dir to destroy_backup_dir * Add the destroy backup option to the menu * Minor CLI message changes
@alichtman Updated based on your review. Pls check 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.
Awesome, a couple quick changes...
shallow_backup.py
Outdated
@@ -109,7 +109,8 @@ def backup_prompt(): | |||
' Back up fonts', | |||
' Back up everything', | |||
' Reinstall configs', | |||
' Reinstall packages' | |||
' Reinstall packages', | |||
' Destroy backups' |
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.
' Destroy backups' | |
' Destroy backup' |
shallow_backup.py
Outdated
@@ -774,6 +790,13 @@ def cli(complete, dotfiles, configs, packages, fonts, old_path, new_path, remote | |||
reinstall_package(packages_path) | |||
elif selection == "reinstall configs": | |||
reinstall_config_files(configs_path) | |||
elif selection == "destroy backups": | |||
if prompt_yes_no("Erase backup directory {}?".format(backup_home_path), Fore.RED): |
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.
if prompt_yes_no("Erase backup directory {}?".format(backup_home_path), Fore.RED): | |
if prompt_yes_no("Erase backup directory: {}?".format(backup_home_path), Fore.RED): |
tests/test_deletes.py
Outdated
from shallow_backup import destroy_backup_dir | ||
|
||
BACKUP_DIR = 'shallow-backup-test-copy-backup-dir' | ||
TEST_BACKUP_TEXT_FILE = BACKUP_DIR + '/test-file.txt' |
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.
Use os.path.join
here instead of hardcoding the path. Windows compatibility is in the works.
Pull from master to resolve those merge conflicts. |
@alichtman Changes applied :> |
Looks good to me. |
Fix #95