From 5b47b3c9e93750e52b8c09724cf37a0435ab7f60 Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Wed, 26 Dec 2018 00:12:30 -0600 Subject: [PATCH 01/30] Exception handling for backups (#206) This commit covers: 1. Specifying the backup path to an existing filename. 2. KeyboardInterrupts at menus and prompts. 3. When backing up packages, failed but installed commands (e.g., ls xxx/.cargo/bin) outputted their error messages to STDOUT. 4. No need to clean up empty backup files now since we don't write to the packages' files if they're not installed. 5. Because of #4, we needed to move npm's 2nd write section into an if so that it wouldn't try to remove a nonexistent file. --- shallow_backup/backup.py | 38 +++++++++++++++-------------------- shallow_backup/git_wrapper.py | 5 +++-- shallow_backup/printing.py | 11 ++++++++-- shallow_backup/prompts.py | 30 +++++++++++++++++++-------- shallow_backup/utils.py | 17 ++++++++++------ 5 files changed, 61 insertions(+), 40 deletions(-) diff --git a/shallow_backup/backup.py b/shallow_backup/backup.py index 5499edd7..aec3cfa9 100644 --- a/shallow_backup/backup.py +++ b/shallow_backup/backup.py @@ -102,59 +102,53 @@ def backup_packages(backup_path, skip=False): print_pkg_mgr_backup(mgr) command = "{} list".format(mgr) dest = "{}/{}_list.txt".format(backup_path, mgr.replace(" ", "-")) - run_cmd_write_stdout(command, dest) + run_cmd_write_stdout(command, dest, mgr) # cargo print_pkg_mgr_backup("cargo") command = "ls {}".format(home_prefix(".cargo/bin/")) dest = "{}/cargo_list.txt".format(backup_path) - run_cmd_write_stdout(command, dest) + run_cmd_write_stdout(command, dest, 'cargo') # pip print_pkg_mgr_backup("pip") command = "pip list --format=freeze" dest = "{}/pip_list.txt".format(backup_path) - run_cmd_write_stdout(command, dest) + run_cmd_write_stdout(command, dest, 'pip') # npm print_pkg_mgr_backup("npm") command = "npm ls --global --parseable=true --depth=0" temp_file_path = "{}/npm_temp_list.txt".format(backup_path) - run_cmd_write_stdout(command, temp_file_path) - npm_dest_file = "{0}/npm_list.txt".format(backup_path) - # Parse npm output - with open(temp_file_path, mode="r+") as temp_file: - # Skip first line of file - temp_file.seek(1) - with open(npm_dest_file, mode="w+") as dest: - for line in temp_file: - dest.write(line.split("/")[-1]) - - os.remove(temp_file_path) + if run_cmd_write_stdout(command, temp_file_path, 'npm') == 0: + npm_dest_file = "{0}/npm_list.txt".format(backup_path) + # Parse npm output + with open(temp_file_path, mode="r+") as temp_file: + # Skip first line of file + temp_file.seek(1) + with open(npm_dest_file, mode="w+") as dest: + for line in temp_file: + dest.write(line.split("/")[-1]) + os.remove(temp_file_path) # atom package manager print_pkg_mgr_backup("Atom") command = "apm list --installed --bare" dest = "{}/apm_list.txt".format(backup_path) - run_cmd_write_stdout(command, dest) + run_cmd_write_stdout(command, dest, 'Atom') # macports print_pkg_mgr_backup("macports") command = "port installed requested" dest = "{}/macports_list.txt".format(backup_path) - run_cmd_write_stdout(command, dest) + run_cmd_write_stdout(command, dest, 'macports') # system installs print_pkg_mgr_backup("System Applications") applications_path = get_applications_dir() command = "ls {}".format(applications_path) dest = "{}/system_apps_list.txt".format(backup_path) - run_cmd_write_stdout(command, dest) - - # Clean up empty package list files - for file in get_abs_path_subfiles(backup_path): - if os.path.getsize(file) == 0: - os.remove(file) + run_cmd_write_stdout(command, dest, 'system applications') def backup_fonts(backup_path, skip=False): diff --git a/shallow_backup/git_wrapper.py b/shallow_backup/git_wrapper.py index b4ccba17..8b56c1ca 100644 --- a/shallow_backup/git_wrapper.py +++ b/shallow_backup/git_wrapper.py @@ -97,6 +97,7 @@ def move_git_repo(source_path, dest_path): dest_git_ignore = os.path.join(dest_path, '.gitignore') git_exists = os.path.exists(dest_git_dir) gitignore_exists = os.path.exists(dest_git_ignore) + if git_exists or gitignore_exists: print_red_bold("Evidence of a git repo has been detected.") if git_exists: @@ -104,7 +105,7 @@ def move_git_repo(source_path, dest_path): if gitignore_exists: print_path_red("A gitignore file already exists here:", dest_git_ignore) print_red_bold("Exiting to prevent accidental deletion of user data.") - sys.exit() + sys.exit(1) git_dir = os.path.join(source_path, '.git') git_ignore_file = os.path.join(source_path, '.gitignore') @@ -114,4 +115,4 @@ def move_git_repo(source_path, dest_path): move(git_ignore_file, dest_path) print_blue_bold("Moving git repo to new location.") except FileNotFoundError: - pass + pass \ No newline at end of file diff --git a/shallow_backup/printing.py b/shallow_backup/printing.py index 289164fb..940c54bf 100644 --- a/shallow_backup/printing.py +++ b/shallow_backup/printing.py @@ -1,3 +1,4 @@ +import sys import inquirer from colorama import Fore, Style from .constants import ProjInfo @@ -86,10 +87,12 @@ def print_pkg_mgr_backup(mgr): print("{}Backing up {}{}{}{}{} packages list...{}".format(Fore.BLUE, Style.BRIGHT, Fore.YELLOW, mgr, Fore.BLUE, Style.NORMAL, Style.RESET_ALL)) - def print_pkg_mgr_reinstall(mgr): print("{}Reinstalling {}{}{}{}{}...{}".format(Fore.BLUE, Style.BRIGHT, Fore.YELLOW, mgr, Fore.BLUE, Style.NORMAL, Style.RESET_ALL)) +def print_pkg_mgr_error(mgr): + print("{}Package {}{}{}{}{} not installed.{}".format(Fore.RED, Style.BRIGHT, Fore.YELLOW, mgr, Fore.RED, + Style.NORMAL, Style.RESET_ALL)) def prompt_yes_no(message, color): """ @@ -102,4 +105,8 @@ def prompt_yes_no(message, color): ] answers = inquirer.prompt(questions) - return answers.get('choice').strip().lower() == 'yes' + + if answers: + return answers.get('choice').strip().lower() == 'yes' + else: + sys.exit(1) diff --git a/shallow_backup/prompts.py b/shallow_backup/prompts.py index 0de734ae..6913e82b 100644 --- a/shallow_backup/prompts.py +++ b/shallow_backup/prompts.py @@ -1,4 +1,5 @@ import os +import sys import inquirer from colorama import Fore, Style from .utils import * @@ -15,13 +16,21 @@ def path_update_prompt(config): current_path = config["backup_path"] print_path_blue("Current shallow-backup path:", current_path) if prompt_yes_no("Would you like to update this?", Fore.GREEN): - print_green_bold("Enter relative or absolute path:") - abs_path = expand_to_abs_path(input()) - print_path_blue("\nUpdating shallow-backup path to:", abs_path) - mkdir_warn_overwrite(abs_path) - move_git_repo(current_path, abs_path) - config["backup_path"] = abs_path - write_config(config) + while True: + print_green_bold("Enter relative or absolute path:") + abs_path = expand_to_abs_path(input()) + + if os.path.isfile(abs_path): + print_path_red('New path is an existing file:', abs_path) + print_red_bold('Please enter a directory.\n') + continue + + print_path_blue("\nUpdating shallow-backup path to:", abs_path) + mkdir_warn_overwrite(abs_path) + move_git_repo(current_path, abs_path) + config["backup_path"] = abs_path + write_config(config) + break def git_url_prompt(repo): @@ -159,4 +168,9 @@ def main_menu_prompt(): ] answers = inquirer.prompt(questions) - return answers.get('choice').strip().lower() + + if answers: + return answers.get('choice').strip().lower() + else: + # KeyboardInterrupts + sys.exit(1) diff --git a/shallow_backup/utils.py b/shallow_backup/utils.py index 9f4cfd28..d71f82b9 100644 --- a/shallow_backup/utils.py +++ b/shallow_backup/utils.py @@ -12,24 +12,30 @@ def run_cmd(command): """ try: if not isinstance(command, list): - process = sp.run(command.split(), stdout=sp.PIPE) + process = sp.run(command.split(), stdout=sp.PIPE, stderr=sp.DEVNULL) return process else: - process = sp.run(command, stdout=sp.PIPE) + process = sp.run(command, stdout=sp.PIPE, stderr=sp.DEVNULL) return process - except FileNotFoundError: # If package manager is missing + except FileNotFoundError: # If package manager is missing return None -def run_cmd_write_stdout(command, filepath): +def run_cmd_write_stdout(command, filepath, package): """ Runs a command and then writes its stdout to a file :param: command str representing command to run + :param: filepath str file to write command's stdout to + :param: package str name of package to print for failed commands """ process = run_cmd(command) - if process: + if process and process.returncode == 0: with open(filepath, "w+") as f: f.write(process.stdout.decode('utf-8')) + return 0 + else: + print_pkg_mgr_error(package) # skip package or say it's not installed? + return 1 def safe_mkdir(directory): @@ -48,7 +54,6 @@ def mkdir_overwrite(path): rmtree(path) os.makedirs(path) - def mkdir_warn_overwrite(path): """ Make destination dir if path doesn't exist, confirm before overwriting if it does. From 1d279fd4bce8a776921b719a7e6f4a64cc35fdd9 Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Wed, 26 Dec 2018 09:02:54 -0600 Subject: [PATCH 02/30] Exception handling for --new_path (#206) I decided to exit here instead of reprompting like in path_update_prompt() because if you're using the --new_path option you decided not to just use the regular path update prompt for some reason. I don't really know why this option's a thing honestly because running shallow-backup with no arguments always prompts you to update the path anyways. --- shallow_backup/__main__.py | 4 ++++ shallow_backup/printing.py | 1 - 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/shallow_backup/__main__.py b/shallow_backup/__main__.py index 79faff8d..d2d026ff 100644 --- a/shallow_backup/__main__.py +++ b/shallow_backup/__main__.py @@ -64,6 +64,10 @@ def cli(show, all, dotfiles, configs, packages, fonts, old_path, new_path, remot # User entered a new path, so update the config if new_path: abs_path = os.path.abspath(new_path) + if os.path.isfile(abs_path): + print_path_red('New path is an existing file:', abs_path) + print_red_bold('Please enter a directory.') + sys.exit(1) print_path_blue("\nUpdating shallow-backup path to:", abs_path) backup_config["backup_path"] = abs_path write_config(backup_config) diff --git a/shallow_backup/printing.py b/shallow_backup/printing.py index 940c54bf..90b3c0da 100644 --- a/shallow_backup/printing.py +++ b/shallow_backup/printing.py @@ -105,7 +105,6 @@ def prompt_yes_no(message, color): ] answers = inquirer.prompt(questions) - if answers: return answers.get('choice').strip().lower() == 'yes' else: From 59ba37364139cd0d06f8e7e3745c3edd68b9d50a Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Wed, 26 Dec 2018 11:17:01 -0600 Subject: [PATCH 03/30] Typo in config dict key --- shallow_backup/reinstall.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index d3ceb63d..8db7b221 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -48,7 +48,7 @@ def backup_prefix(path): return os.path.join(configs_path, path) config = get_config() - for dest_path, backup_loc in config["configs_mapping"].items(): + for dest_path, backup_loc in config["config_mapping"].items(): dest_path = quote(dest_path) path_to_backup = quote(backup_prefix(backup_loc)) # TODO: REFACTOR WITH GENERIC COPY FUNCTION. From a9b195648bfe9746e0e33bce5de41a662141ff9c Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Wed, 26 Dec 2018 20:51:29 -0600 Subject: [PATCH 04/30] Fixed reinstalling packages w/ no package backups Also got rid of unnecessary inner function. --- shallow_backup/reinstall.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index 8db7b221..7d1060f4 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -5,6 +5,8 @@ from .printing import * from .compatibility import * from .config import get_config +from .prompts import prompt_yes_no +from .backup import backup_packages from shutil import copytree, copyfile # NOTE: Naming convention is like this since the CLI flags would otherwise @@ -44,13 +46,10 @@ def reinstall_configs_sb(configs_path): """ print_section_header("REINSTALLING CONFIG FILES", Fore.BLUE) - def backup_prefix(path): - return os.path.join(configs_path, path) - config = get_config() for dest_path, backup_loc in config["config_mapping"].items(): dest_path = quote(dest_path) - path_to_backup = quote(backup_prefix(backup_loc)) + path_to_backup = quote(os.path.join(configs_path, backup_loc)) # TODO: REFACTOR WITH GENERIC COPY FUNCTION. if os.path.isdir(path_to_backup): copytree(path_to_backup, dest_path) @@ -64,6 +63,13 @@ def reinstall_packages_sb(packages_path): """ Reinstall all packages from the files in backup/installs. """ + if not os.path.isdir(packages_path): + print_red_bold('No package backups found.') + if prompt_yes_no("Would you like to backup packages?", Fore.GREEN): + backup_packages(packages_path, skip=True) + else: + return + print_section_header("REINSTALLING PACKAGES", Fore.BLUE) # Figure out which install lists they have saved From ecbfbe53283545c57433f2195d832e761667f9c9 Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Wed, 26 Dec 2018 21:32:52 -0600 Subject: [PATCH 05/30] coverage: trailing space --- shallow_backup/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shallow_backup/utils.py b/shallow_backup/utils.py index d71f82b9..f4a4a284 100644 --- a/shallow_backup/utils.py +++ b/shallow_backup/utils.py @@ -17,7 +17,7 @@ def run_cmd(command): else: process = sp.run(command, stdout=sp.PIPE, stderr=sp.DEVNULL) return process - except FileNotFoundError: # If package manager is missing + except FileNotFoundError: # If package manager is missing return None From 289cb65bce5f74af1cf2d7db040cd2b2e45070a5 Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 15:11:47 -0600 Subject: [PATCH 06/30] Added EOF blank line --- shallow_backup/git_wrapper.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shallow_backup/git_wrapper.py b/shallow_backup/git_wrapper.py index 8b56c1ca..698eb3fd 100644 --- a/shallow_backup/git_wrapper.py +++ b/shallow_backup/git_wrapper.py @@ -115,4 +115,5 @@ def move_git_repo(source_path, dest_path): move(git_ignore_file, dest_path) print_blue_bold("Moving git repo to new location.") except FileNotFoundError: - pass \ No newline at end of file + pass + From f436375de7bbb36474edb07ed205e90e7343f3d1 Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 15:15:30 -0600 Subject: [PATCH 07/30] Updated to exit after no package backups are found --- shallow_backup/reinstall.py | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index 7d1060f4..1736afe9 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -5,8 +5,6 @@ from .printing import * from .compatibility import * from .config import get_config -from .prompts import prompt_yes_no -from .backup import backup_packages from shutil import copytree, copyfile # NOTE: Naming convention is like this since the CLI flags would otherwise @@ -65,10 +63,7 @@ def reinstall_packages_sb(packages_path): """ if not os.path.isdir(packages_path): print_red_bold('No package backups found.') - if prompt_yes_no("Would you like to backup packages?", Fore.GREEN): - backup_packages(packages_path, skip=True) - else: - return + sys.exit(1) print_section_header("REINSTALLING PACKAGES", Fore.BLUE) From 41c6f99fadb2f4f8166b763a48d82caed4b07ace Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 15:18:04 -0600 Subject: [PATCH 08/30] PEP8 --- shallow_backup/printing.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/shallow_backup/printing.py b/shallow_backup/printing.py index 90b3c0da..a13df748 100644 --- a/shallow_backup/printing.py +++ b/shallow_backup/printing.py @@ -87,13 +87,16 @@ def print_pkg_mgr_backup(mgr): print("{}Backing up {}{}{}{}{} packages list...{}".format(Fore.BLUE, Style.BRIGHT, Fore.YELLOW, mgr, Fore.BLUE, Style.NORMAL, Style.RESET_ALL)) + def print_pkg_mgr_reinstall(mgr): print("{}Reinstalling {}{}{}{}{}...{}".format(Fore.BLUE, Style.BRIGHT, Fore.YELLOW, mgr, Fore.BLUE, Style.NORMAL, Style.RESET_ALL)) + def print_pkg_mgr_error(mgr): print("{}Package {}{}{}{}{} not installed.{}".format(Fore.RED, Style.BRIGHT, Fore.YELLOW, mgr, Fore.RED, Style.NORMAL, Style.RESET_ALL)) + def prompt_yes_no(message, color): """ Print question and return True or False depending on user selection from list. @@ -109,3 +112,4 @@ def prompt_yes_no(message, color): return answers.get('choice').strip().lower() == 'yes' else: sys.exit(1) + From 5a96b6cd87d7740dcd15d21ca9d99328d9c33989 Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 15:19:55 -0600 Subject: [PATCH 09/30] got rid of extra EOL blank line --- shallow_backup/printing.py | 1 - 1 file changed, 1 deletion(-) diff --git a/shallow_backup/printing.py b/shallow_backup/printing.py index a13df748..f61e9ffa 100644 --- a/shallow_backup/printing.py +++ b/shallow_backup/printing.py @@ -112,4 +112,3 @@ def prompt_yes_no(message, color): return answers.get('choice').strip().lower() == 'yes' else: sys.exit(1) - From cb2b47ea9e5e8736783e610ae459e30a8a6bb305 Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 15:20:49 -0600 Subject: [PATCH 10/30] break to return --- shallow_backup/prompts.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shallow_backup/prompts.py b/shallow_backup/prompts.py index 6913e82b..108dda03 100644 --- a/shallow_backup/prompts.py +++ b/shallow_backup/prompts.py @@ -30,7 +30,7 @@ def path_update_prompt(config): move_git_repo(current_path, abs_path) config["backup_path"] = abs_path write_config(config) - break + return def git_url_prompt(repo): From 28f40b6553b628f6dc4a463f010dc0ec15c0a7de Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 15:26:55 -0600 Subject: [PATCH 11/30] Refactored out existing file check into utils.py --- shallow_backup/__main__.py | 10 ++++++---- shallow_backup/prompts.py | 5 ++--- shallow_backup/utils.py | 6 ++++++ 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/shallow_backup/__main__.py b/shallow_backup/__main__.py index d2d026ff..21827f52 100644 --- a/shallow_backup/__main__.py +++ b/shallow_backup/__main__.py @@ -3,7 +3,9 @@ from .prompts import * from .reinstall import * from .git_wrapper import * -from .utils import mkdir_warn_overwrite, destroy_backup_dir, expand_to_abs_path +from .utils import ( + mkdir_warn_overwrite, destroy_backup_dir, expand_to_abs_path, + existing_file_check) # custom help options @@ -64,10 +66,10 @@ def cli(show, all, dotfiles, configs, packages, fonts, old_path, new_path, remot # User entered a new path, so update the config if new_path: abs_path = os.path.abspath(new_path) - if os.path.isfile(abs_path): - print_path_red('New path is an existing file:', abs_path) - print_red_bold('Please enter a directory.') + + if existing_file_check(abs_path): sys.exit(1) + print_path_blue("\nUpdating shallow-backup path to:", abs_path) backup_config["backup_path"] = abs_path write_config(backup_config) diff --git a/shallow_backup/prompts.py b/shallow_backup/prompts.py index 108dda03..ac67eae8 100644 --- a/shallow_backup/prompts.py +++ b/shallow_backup/prompts.py @@ -6,6 +6,7 @@ from .printing import * from .config import * from .git_wrapper import git_set_remote, move_git_repo +from .utils import existing_file_check def path_update_prompt(config): @@ -20,9 +21,7 @@ def path_update_prompt(config): print_green_bold("Enter relative or absolute path:") abs_path = expand_to_abs_path(input()) - if os.path.isfile(abs_path): - print_path_red('New path is an existing file:', abs_path) - print_red_bold('Please enter a directory.\n') + if existing_file_check(abs_path): continue print_path_blue("\nUpdating shallow-backup path to:", abs_path) diff --git a/shallow_backup/utils.py b/shallow_backup/utils.py index f4a4a284..1fafad33 100644 --- a/shallow_backup/utils.py +++ b/shallow_backup/utils.py @@ -38,6 +38,12 @@ def run_cmd_write_stdout(command, filepath, package): return 1 +def existing_file_check(abs_path): + if os.path.isfile(abs_path): + print_path_red('New path is an existing file:', abs_path) + print_red_bold('Please enter a directory.\n') + + def safe_mkdir(directory): """ Makes directory if it doesn't already exist. From fb5cef65589535896aa19c3459d9253b11979e0a Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 16:19:57 -0600 Subject: [PATCH 12/30] PEP8 --- shallow_backup/utils.py | 1 + 1 file changed, 1 insertion(+) diff --git a/shallow_backup/utils.py b/shallow_backup/utils.py index 1fafad33..1d11cc4b 100644 --- a/shallow_backup/utils.py +++ b/shallow_backup/utils.py @@ -60,6 +60,7 @@ def mkdir_overwrite(path): rmtree(path) os.makedirs(path) + def mkdir_warn_overwrite(path): """ Make destination dir if path doesn't exist, confirm before overwriting if it does. From 5054d894872c1bc0c27126d2ae257230bb6c759a Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 16:46:18 -0600 Subject: [PATCH 13/30] Updated backup prompt to not be literal satan --- shallow_backup/printing.py | 5 +++-- shallow_backup/prompts.py | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/shallow_backup/printing.py b/shallow_backup/printing.py index f61e9ffa..9e473c9b 100644 --- a/shallow_backup/printing.py +++ b/shallow_backup/printing.py @@ -97,13 +97,14 @@ def print_pkg_mgr_error(mgr): Style.NORMAL, Style.RESET_ALL)) -def prompt_yes_no(message, color): +def prompt_yes_no(message, color, invert=False): """ Print question and return True or False depending on user selection from list. """ + choices = (' No', ' Yes') if invert else (' Yes', ' No') questions = [inquirer.List('choice', message=color + Style.BRIGHT + message + Fore.BLUE, - choices=[' Yes', ' No'], + choices=choices, ) ] diff --git a/shallow_backup/prompts.py b/shallow_backup/prompts.py index ac67eae8..c5ec9221 100644 --- a/shallow_backup/prompts.py +++ b/shallow_backup/prompts.py @@ -16,7 +16,7 @@ def path_update_prompt(config): """ current_path = config["backup_path"] print_path_blue("Current shallow-backup path:", current_path) - if prompt_yes_no("Would you like to update this?", Fore.GREEN): + if prompt_yes_no("Would you like to update this?", Fore.GREEN, invert=True): while True: print_green_bold("Enter relative or absolute path:") abs_path = expand_to_abs_path(input()) From 11434b694bd082a221c20ff26d3eeb908b97ebf3 Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 16:49:36 -0600 Subject: [PATCH 14/30] Added check for existing but empty package directories --- shallow_backup/reinstall.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index 1736afe9..b293bcb4 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -61,7 +61,8 @@ def reinstall_packages_sb(packages_path): """ Reinstall all packages from the files in backup/installs. """ - if not os.path.isdir(packages_path): + if not os.path.isdir(packages_path) or (os.path.isdir(packages_path) and + not os.listdir(packages_path): print_red_bold('No package backups found.') sys.exit(1) From 3783008ac84fb8d1ec1d813b7ee9c2e50e0a8cc3 Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 17:06:51 -0600 Subject: [PATCH 15/30] Fixed empty dir check and modified package error message --- shallow_backup/printing.py | 12 ++++++------ shallow_backup/reinstall.py | 2 +- shallow_backup/utils.py | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/shallow_backup/printing.py b/shallow_backup/printing.py index 9e473c9b..f6653d0f 100644 --- a/shallow_backup/printing.py +++ b/shallow_backup/printing.py @@ -84,17 +84,17 @@ def print_section_header(title, color): def print_pkg_mgr_backup(mgr): - print("{}Backing up {}{}{}{}{} packages list...{}".format(Fore.BLUE, Style.BRIGHT, Fore.YELLOW, mgr, Fore.BLUE, - Style.NORMAL, Style.RESET_ALL)) + print("{}Backing up {}{}{}{}{} packages list...{}".format(Fore.BLUE, Style.BRIGHT, Fore.YELLOW, mgr, + Fore.BLUE, Style.NORMAL, Style.RESET_ALL)) def print_pkg_mgr_reinstall(mgr): - print("{}Reinstalling {}{}{}{}{}...{}".format(Fore.BLUE, Style.BRIGHT, Fore.YELLOW, mgr, Fore.BLUE, Style.NORMAL, Style.RESET_ALL)) + print("{}Reinstalling {}{}{}{}{}...{}".format(Fore.BLUE, Style.BRIGHT, Fore.YELLOW, + mgr, Fore.BLUE, Style.NORMAL, Style.RESET_ALL)) -def print_pkg_mgr_error(mgr): - print("{}Package {}{}{}{}{} not installed.{}".format(Fore.RED, Style.BRIGHT, Fore.YELLOW, mgr, Fore.RED, - Style.NORMAL, Style.RESET_ALL)) +def print_pkg_mgr_error(cmd): + print("{}An error occurred while running:{} $ {}".format(Fore.RED, Style.RESET_ALL, cmd)) def prompt_yes_no(message, color, invert=False): diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index b293bcb4..e2e78c00 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -62,7 +62,7 @@ def reinstall_packages_sb(packages_path): Reinstall all packages from the files in backup/installs. """ if not os.path.isdir(packages_path) or (os.path.isdir(packages_path) and - not os.listdir(packages_path): + not os.listdir(packages_path)): print_red_bold('No package backups found.') sys.exit(1) diff --git a/shallow_backup/utils.py b/shallow_backup/utils.py index 1d11cc4b..230a9ad8 100644 --- a/shallow_backup/utils.py +++ b/shallow_backup/utils.py @@ -34,7 +34,7 @@ def run_cmd_write_stdout(command, filepath, package): f.write(process.stdout.decode('utf-8')) return 0 else: - print_pkg_mgr_error(package) # skip package or say it's not installed? + print_pkg_mgr_error(command) # skip package or say it's not installed? return 1 From ef21b4121de4566af00d7e45a499cfb5e7f73fd5 Mon Sep 17 00:00:00 2001 From: Aaron Lichtman Date: Tue, 1 Jan 2019 17:08:39 -0600 Subject: [PATCH 16/30] Updated existing file check function name Co-Authored-By: bl0nd --- shallow_backup/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shallow_backup/utils.py b/shallow_backup/utils.py index 1d11cc4b..ec83750e 100644 --- a/shallow_backup/utils.py +++ b/shallow_backup/utils.py @@ -38,7 +38,7 @@ def run_cmd_write_stdout(command, filepath, package): return 1 -def existing_file_check(abs_path): +def new_dir_is_valid(abs_path): if os.path.isfile(abs_path): print_path_red('New path is an existing file:', abs_path) print_red_bold('Please enter a directory.\n') From 6947433a0765d4a3836a0f3062373ec56187c9fb Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 21:20:40 -0600 Subject: [PATCH 17/30] Modified empty directory check condition --- shallow_backup/reinstall.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index e2e78c00..560744eb 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -61,8 +61,7 @@ def reinstall_packages_sb(packages_path): """ Reinstall all packages from the files in backup/installs. """ - if not os.path.isdir(packages_path) or (os.path.isdir(packages_path) and - not os.listdir(packages_path)): + if not os.path.isdir(packages_path) or not os.listdir(packages_path): print_red_bold('No package backups found.') sys.exit(1) From 89d425f2b98d7a3142562b4c527033617eb24042 Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 21:30:45 -0600 Subject: [PATCH 18/30] ternary up in here --- shallow_backup/printing.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/shallow_backup/printing.py b/shallow_backup/printing.py index f6653d0f..d750fcb5 100644 --- a/shallow_backup/printing.py +++ b/shallow_backup/printing.py @@ -101,10 +101,9 @@ def prompt_yes_no(message, color, invert=False): """ Print question and return True or False depending on user selection from list. """ - choices = (' No', ' Yes') if invert else (' Yes', ' No') questions = [inquirer.List('choice', message=color + Style.BRIGHT + message + Fore.BLUE, - choices=choices, + choices=(' No', ' Yes') if invert else (' Yes', ' No'), ) ] From 65ae865d72f54e67371ee21b3b27c0f00b0a8d8c Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 21:33:38 -0600 Subject: [PATCH 19/30] renamed print_pkg_mgr_error() --- shallow_backup/printing.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/shallow_backup/printing.py b/shallow_backup/printing.py index d750fcb5..a551d1bc 100644 --- a/shallow_backup/printing.py +++ b/shallow_backup/printing.py @@ -93,7 +93,7 @@ def print_pkg_mgr_reinstall(mgr): mgr, Fore.BLUE, Style.NORMAL, Style.RESET_ALL)) -def print_pkg_mgr_error(cmd): +def print_shell_cmd_error(cmd): print("{}An error occurred while running:{} $ {}".format(Fore.RED, Style.RESET_ALL, cmd)) @@ -103,7 +103,7 @@ def prompt_yes_no(message, color, invert=False): """ questions = [inquirer.List('choice', message=color + Style.BRIGHT + message + Fore.BLUE, - choices=(' No', ' Yes') if invert else (' Yes', ' No'), + choices=(' No', ' Yes') if invert else (' Yes', ' No') ) ] From 551f4a327922b777d149a8104976ee6945a44560 Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 21:37:49 -0600 Subject: [PATCH 20/30] modified package error message --- shallow_backup/printing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shallow_backup/printing.py b/shallow_backup/printing.py index a551d1bc..b7cf7d01 100644 --- a/shallow_backup/printing.py +++ b/shallow_backup/printing.py @@ -94,7 +94,7 @@ def print_pkg_mgr_reinstall(mgr): def print_shell_cmd_error(cmd): - print("{}An error occurred while running:{} $ {}".format(Fore.RED, Style.RESET_ALL, cmd)) + print("{}$ {}".format(print_path_red('An error occurred while running: ') cmd)) def prompt_yes_no(message, color, invert=False): From 2b9067824f10f4285d1520ca292c215a803d4435 Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 21:44:07 -0600 Subject: [PATCH 21/30] removed unnecessary parameters and updated function calls --- shallow_backup/__main__.py | 4 ++-- shallow_backup/backup.py | 14 +++++++------- shallow_backup/prompts.py | 4 ++-- shallow_backup/utils.py | 3 +-- 4 files changed, 12 insertions(+), 13 deletions(-) diff --git a/shallow_backup/__main__.py b/shallow_backup/__main__.py index 21827f52..89a1d977 100644 --- a/shallow_backup/__main__.py +++ b/shallow_backup/__main__.py @@ -5,7 +5,7 @@ from .git_wrapper import * from .utils import ( mkdir_warn_overwrite, destroy_backup_dir, expand_to_abs_path, - existing_file_check) + new_dir_is_valid) # custom help options @@ -67,7 +67,7 @@ def cli(show, all, dotfiles, configs, packages, fonts, old_path, new_path, remot if new_path: abs_path = os.path.abspath(new_path) - if existing_file_check(abs_path): + if new_dir_is_valid(abs_path): sys.exit(1) print_path_blue("\nUpdating shallow-backup path to:", abs_path) diff --git a/shallow_backup/backup.py b/shallow_backup/backup.py index aec3cfa9..701a59e1 100644 --- a/shallow_backup/backup.py +++ b/shallow_backup/backup.py @@ -102,25 +102,25 @@ def backup_packages(backup_path, skip=False): print_pkg_mgr_backup(mgr) command = "{} list".format(mgr) dest = "{}/{}_list.txt".format(backup_path, mgr.replace(" ", "-")) - run_cmd_write_stdout(command, dest, mgr) + run_cmd_write_stdout(command, dest) # cargo print_pkg_mgr_backup("cargo") command = "ls {}".format(home_prefix(".cargo/bin/")) dest = "{}/cargo_list.txt".format(backup_path) - run_cmd_write_stdout(command, dest, 'cargo') + run_cmd_write_stdout(command, dest) # pip print_pkg_mgr_backup("pip") command = "pip list --format=freeze" dest = "{}/pip_list.txt".format(backup_path) - run_cmd_write_stdout(command, dest, 'pip') + run_cmd_write_stdout(command, dest) # npm print_pkg_mgr_backup("npm") command = "npm ls --global --parseable=true --depth=0" temp_file_path = "{}/npm_temp_list.txt".format(backup_path) - if run_cmd_write_stdout(command, temp_file_path, 'npm') == 0: + if run_cmd_write_stdout(command, temp_file_path) == 0: npm_dest_file = "{0}/npm_list.txt".format(backup_path) # Parse npm output with open(temp_file_path, mode="r+") as temp_file: @@ -135,20 +135,20 @@ def backup_packages(backup_path, skip=False): print_pkg_mgr_backup("Atom") command = "apm list --installed --bare" dest = "{}/apm_list.txt".format(backup_path) - run_cmd_write_stdout(command, dest, 'Atom') + run_cmd_write_stdout(command, dest) # macports print_pkg_mgr_backup("macports") command = "port installed requested" dest = "{}/macports_list.txt".format(backup_path) - run_cmd_write_stdout(command, dest, 'macports') + run_cmd_write_stdout(command, dest) # system installs print_pkg_mgr_backup("System Applications") applications_path = get_applications_dir() command = "ls {}".format(applications_path) dest = "{}/system_apps_list.txt".format(backup_path) - run_cmd_write_stdout(command, dest, 'system applications') + run_cmd_write_stdout(command, dest) def backup_fonts(backup_path, skip=False): diff --git a/shallow_backup/prompts.py b/shallow_backup/prompts.py index c5ec9221..20421413 100644 --- a/shallow_backup/prompts.py +++ b/shallow_backup/prompts.py @@ -6,7 +6,7 @@ from .printing import * from .config import * from .git_wrapper import git_set_remote, move_git_repo -from .utils import existing_file_check +from .utils import new_dir_is_valid def path_update_prompt(config): @@ -21,7 +21,7 @@ def path_update_prompt(config): print_green_bold("Enter relative or absolute path:") abs_path = expand_to_abs_path(input()) - if existing_file_check(abs_path): + if new_dir_is_valid(abs_path): continue print_path_blue("\nUpdating shallow-backup path to:", abs_path) diff --git a/shallow_backup/utils.py b/shallow_backup/utils.py index f4122097..e5060043 100644 --- a/shallow_backup/utils.py +++ b/shallow_backup/utils.py @@ -21,12 +21,11 @@ def run_cmd(command): return None -def run_cmd_write_stdout(command, filepath, package): +def run_cmd_write_stdout(command, filepath): """ Runs a command and then writes its stdout to a file :param: command str representing command to run :param: filepath str file to write command's stdout to - :param: package str name of package to print for failed commands """ process = run_cmd(command) if process and process.returncode == 0: From e16c9f01b39ba10648033cba5e13bf727732f554 Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 21:45:11 -0600 Subject: [PATCH 22/30] missing comma --- shallow_backup/printing.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shallow_backup/printing.py b/shallow_backup/printing.py index b7cf7d01..a93c986f 100644 --- a/shallow_backup/printing.py +++ b/shallow_backup/printing.py @@ -94,7 +94,7 @@ def print_pkg_mgr_reinstall(mgr): def print_shell_cmd_error(cmd): - print("{}$ {}".format(print_path_red('An error occurred while running: ') cmd)) + print("{}$ {}".format(print_path_red('An error occurred while running: '), cmd)) def prompt_yes_no(message, color, invert=False): From 6584ba7b071b829777fc79b838bd2963996c652c Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 22:10:11 -0600 Subject: [PATCH 23/30] removed print_shell_cmd_error --- shallow_backup/printing.py | 4 ---- shallow_backup/utils.py | 3 +-- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/shallow_backup/printing.py b/shallow_backup/printing.py index a93c986f..aeaf73f8 100644 --- a/shallow_backup/printing.py +++ b/shallow_backup/printing.py @@ -93,10 +93,6 @@ def print_pkg_mgr_reinstall(mgr): mgr, Fore.BLUE, Style.NORMAL, Style.RESET_ALL)) -def print_shell_cmd_error(cmd): - print("{}$ {}".format(print_path_red('An error occurred while running: '), cmd)) - - def prompt_yes_no(message, color, invert=False): """ Print question and return True or False depending on user selection from list. diff --git a/shallow_backup/utils.py b/shallow_backup/utils.py index e5060043..aa59aa15 100644 --- a/shallow_backup/utils.py +++ b/shallow_backup/utils.py @@ -31,9 +31,8 @@ def run_cmd_write_stdout(command, filepath): if process and process.returncode == 0: with open(filepath, "w+") as f: f.write(process.stdout.decode('utf-8')) - return 0 else: - print_pkg_mgr_error(command) # skip package or say it's not installed? + print_path_red("An error occurred while running: $", command) # skip package or say it's not installed? return 1 From eaf0b9dab117b1b5d86d0f0f44ce0b1dfd2e0a6c Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 22:28:41 -0600 Subject: [PATCH 24/30] Updated new_dir_is_valid to return bool --- shallow_backup/backup.py | 2 +- shallow_backup/prompts.py | 2 +- shallow_backup/utils.py | 2 ++ 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/shallow_backup/backup.py b/shallow_backup/backup.py index 701a59e1..4b16f887 100644 --- a/shallow_backup/backup.py +++ b/shallow_backup/backup.py @@ -120,7 +120,7 @@ def backup_packages(backup_path, skip=False): print_pkg_mgr_backup("npm") command = "npm ls --global --parseable=true --depth=0" temp_file_path = "{}/npm_temp_list.txt".format(backup_path) - if run_cmd_write_stdout(command, temp_file_path) == 0: + if not run_cmd_write_stdout(command, temp_file_path): npm_dest_file = "{0}/npm_list.txt".format(backup_path) # Parse npm output with open(temp_file_path, mode="r+") as temp_file: diff --git a/shallow_backup/prompts.py b/shallow_backup/prompts.py index 20421413..2e75d3e8 100644 --- a/shallow_backup/prompts.py +++ b/shallow_backup/prompts.py @@ -21,7 +21,7 @@ def path_update_prompt(config): print_green_bold("Enter relative or absolute path:") abs_path = expand_to_abs_path(input()) - if new_dir_is_valid(abs_path): + if not new_dir_is_valid(abs_path): continue print_path_blue("\nUpdating shallow-backup path to:", abs_path) diff --git a/shallow_backup/utils.py b/shallow_backup/utils.py index aa59aa15..ecab3a59 100644 --- a/shallow_backup/utils.py +++ b/shallow_backup/utils.py @@ -40,6 +40,8 @@ def new_dir_is_valid(abs_path): if os.path.isfile(abs_path): print_path_red('New path is an existing file:', abs_path) print_red_bold('Please enter a directory.\n') + return False + return True def safe_mkdir(directory): From ff1233adcbd4a3b0720889f3cca03ee2f2ff4e8e Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 22:43:23 -0600 Subject: [PATCH 25/30] updated to reflect new new_dir_is_valid() --- shallow_backup/__main__.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shallow_backup/__main__.py b/shallow_backup/__main__.py index 89a1d977..076ebfc8 100644 --- a/shallow_backup/__main__.py +++ b/shallow_backup/__main__.py @@ -67,7 +67,7 @@ def cli(show, all, dotfiles, configs, packages, fonts, old_path, new_path, remot if new_path: abs_path = os.path.abspath(new_path) - if new_dir_is_valid(abs_path): + if not new_dir_is_valid(abs_path): sys.exit(1) print_path_blue("\nUpdating shallow-backup path to:", abs_path) From ee9343da35601a9a5767957991ea4dd19360870c Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 22:49:40 -0600 Subject: [PATCH 26/30] removed comment --- shallow_backup/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shallow_backup/utils.py b/shallow_backup/utils.py index ecab3a59..b53d92dc 100644 --- a/shallow_backup/utils.py +++ b/shallow_backup/utils.py @@ -32,7 +32,7 @@ def run_cmd_write_stdout(command, filepath): with open(filepath, "w+") as f: f.write(process.stdout.decode('utf-8')) else: - print_path_red("An error occurred while running: $", command) # skip package or say it's not installed? + print_path_red("An error occurred while running: $", command) return 1 From 6c7f9fadd91c616a78171d43564e4234f1cb4f1c Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 22:52:23 -0600 Subject: [PATCH 27/30] Updated error message --- shallow_backup/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shallow_backup/utils.py b/shallow_backup/utils.py index b53d92dc..c55c072e 100644 --- a/shallow_backup/utils.py +++ b/shallow_backup/utils.py @@ -38,7 +38,7 @@ def run_cmd_write_stdout(command, filepath): def new_dir_is_valid(abs_path): if os.path.isfile(abs_path): - print_path_red('New path is an existing file:', abs_path) + print_path_red('New path is a file:', abs_path) print_red_bold('Please enter a directory.\n') return False return True From 92adb5b9524c5b12a6ce765e371607f3ad390f95 Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 23:16:57 -0600 Subject: [PATCH 28/30] moved empty backup dir check into function --- shallow_backup/reinstall.py | 12 +++++++----- shallow_backup/utils.py | 6 ++++++ 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index 560744eb..3b7bbdcb 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -1,7 +1,7 @@ import os from shlex import quote from colorama import Fore -from .utils import run_cmd, get_abs_path_subfiles +from .utils import run_cmd, get_abs_path_subfiles, empty_backup_dir_check from .printing import * from .compatibility import * from .config import get_config @@ -15,7 +15,9 @@ def reinstall_dots_sb(dots_path): """ Reinstall all dotfiles and folders by copying them to the home dir. """ + empty_backup_dir_check(dots_path) print_section_header("REINSTALLING DOTFILES", Fore.BLUE) + home_path = os.path.expanduser('~') for file in get_abs_path_subfiles(dots_path): if os.path.isdir(file): @@ -29,7 +31,9 @@ def reinstall_fonts_sb(fonts_path): """ Reinstall all fonts. """ + empty_backup_dir_check(fonts_path) print_section_header("REINSTALLING FONTS", Fore.BLUE) + # Copy every file in fonts_path to ~/Library/Fonts for font in get_abs_path_subfiles(fonts_path): font_lib_path = get_fonts_dir() @@ -42,6 +46,7 @@ def reinstall_configs_sb(configs_path): """ Reinstall all configs from the backup. """ + empty_backup_dir_check(configs_path) print_section_header("REINSTALLING CONFIG FILES", Fore.BLUE) config = get_config() @@ -61,10 +66,7 @@ def reinstall_packages_sb(packages_path): """ Reinstall all packages from the files in backup/installs. """ - if not os.path.isdir(packages_path) or not os.listdir(packages_path): - print_red_bold('No package backups found.') - sys.exit(1) - + empty_backup_dir_check(packages_path) print_section_header("REINSTALLING PACKAGES", Fore.BLUE) # Figure out which install lists they have saved diff --git a/shallow_backup/utils.py b/shallow_backup/utils.py index c55c072e..bc241af7 100644 --- a/shallow_backup/utils.py +++ b/shallow_backup/utils.py @@ -78,6 +78,12 @@ def mkdir_warn_overwrite(path): print_path_blue("Created directory:", path) +def empty_backup_dir_check(backup_path): + if not os.path.isdir(backup_path) or not os.listdir(backup_path): + print_red_bold('No package backups found.') + sys.exit(1) + + def destroy_backup_dir(backup_path): """ Deletes the backup directory and its content From e9ae1aa36c99e372c49438a3236c9f89580ab694 Mon Sep 17 00:00:00 2001 From: Jason Phan Date: Tue, 1 Jan 2019 23:22:58 -0600 Subject: [PATCH 29/30] updated empty_backup_dir_check() message --- shallow_backup/reinstall.py | 8 ++++---- shallow_backup/utils.py | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index 3b7bbdcb..d0feb947 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -15,7 +15,7 @@ def reinstall_dots_sb(dots_path): """ Reinstall all dotfiles and folders by copying them to the home dir. """ - empty_backup_dir_check(dots_path) + empty_backup_dir_check(dots_path, 'dotfile') print_section_header("REINSTALLING DOTFILES", Fore.BLUE) home_path = os.path.expanduser('~') @@ -31,7 +31,7 @@ def reinstall_fonts_sb(fonts_path): """ Reinstall all fonts. """ - empty_backup_dir_check(fonts_path) + empty_backup_dir_check(fonts_path, 'font') print_section_header("REINSTALLING FONTS", Fore.BLUE) # Copy every file in fonts_path to ~/Library/Fonts @@ -46,7 +46,7 @@ def reinstall_configs_sb(configs_path): """ Reinstall all configs from the backup. """ - empty_backup_dir_check(configs_path) + empty_backup_dir_check(configs_path, 'config') print_section_header("REINSTALLING CONFIG FILES", Fore.BLUE) config = get_config() @@ -66,7 +66,7 @@ def reinstall_packages_sb(packages_path): """ Reinstall all packages from the files in backup/installs. """ - empty_backup_dir_check(packages_path) + empty_backup_dir_check(packages_path, 'package') print_section_header("REINSTALLING PACKAGES", Fore.BLUE) # Figure out which install lists they have saved diff --git a/shallow_backup/utils.py b/shallow_backup/utils.py index bc241af7..de1a98c7 100644 --- a/shallow_backup/utils.py +++ b/shallow_backup/utils.py @@ -78,9 +78,9 @@ def mkdir_warn_overwrite(path): print_path_blue("Created directory:", path) -def empty_backup_dir_check(backup_path): +def empty_backup_dir_check(backup_path, backup_type): if not os.path.isdir(backup_path) or not os.listdir(backup_path): - print_red_bold('No package backups found.') + print_red_bold('No package {} found.'.format(backup_type)) sys.exit(1) From 20317410c886c8cf4ea897711e0a802b59774475 Mon Sep 17 00:00:00 2001 From: Aaron Lichtman Date: Tue, 1 Jan 2019 23:29:35 -0600 Subject: [PATCH 30/30] Fix error message. --- shallow_backup/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shallow_backup/utils.py b/shallow_backup/utils.py index de1a98c7..589294da 100644 --- a/shallow_backup/utils.py +++ b/shallow_backup/utils.py @@ -80,7 +80,7 @@ def mkdir_warn_overwrite(path): def empty_backup_dir_check(backup_path, backup_type): if not os.path.isdir(backup_path) or not os.listdir(backup_path): - print_red_bold('No package {} found.'.format(backup_type)) + print_red_bold('No {} backup found.'.format(backup_type)) sys.exit(1)