Skip to content
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

Merged

Conversation

neequole
Copy link

Fix #95

Copy link
Owner

@alichtman alichtman left a 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.

@@ -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):
Copy link
Owner

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?

def clean_backup_dir(backup_path):
try:
shutil.rmtree(backup_path)
print("{} Deleted backup directory {} {}".format(Fore.BLUE, backup_path, Style.RESET_ALL))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. We should use Fore.RED and Style.BRIGHT here since removal is a "dangerous" action.
  2. I usually put print statements before the action, and use the infinitive tense. "Deleting" and then I finish the line with ellipsis.

@@ -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):
Copy link
Owner

@alichtman alichtman Oct 19, 2018

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

  1. Let's change the flag to -destroy_backup since that's a lot clearer.
  2. Then we should refactor the other method names as needed.
  3. Let's add this option to the menu.

Copy link
Contributor

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()

Copy link
Owner

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
@ntibay
Copy link
Contributor

ntibay commented Oct 19, 2018

@alichtman Updated based on your review. Pls check thanks!

Copy link
Owner

@alichtman alichtman left a 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...

@@ -109,7 +109,8 @@ def backup_prompt():
' Back up fonts',
' Back up everything',
' Reinstall configs',
' Reinstall packages'
' Reinstall packages',
' Destroy backups'
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
' Destroy backups'
' Destroy backup'

@@ -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):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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):

from shallow_backup import destroy_backup_dir

BACKUP_DIR = 'shallow-backup-test-copy-backup-dir'
TEST_BACKUP_TEXT_FILE = BACKUP_DIR + '/test-file.txt'
Copy link
Owner

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.

@alichtman
Copy link
Owner

Pull from master to resolve those merge conflicts.

@neequole
Copy link
Author

@alichtman Changes applied :>

@alichtman
Copy link
Owner

Looks good to me.

@alichtman alichtman merged commit 0da0e6a into alichtman:master Oct 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants