Skip to content

Commit

Permalink
Merge branch 'master' into add-ruby-support
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-coutinho committed Jul 21, 2021
2 parents e32a5fa + dbd87d7 commit b5cc330
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 38 deletions.
48 changes: 24 additions & 24 deletions shallow_backup/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,43 +148,43 @@ def cli(add_dot, backup_configs_flag, delete_config, destroy_backup, backup_dots
git_add_all_commit_push(repo, "fonts")
# No CL options, show action menu and process selected option.
else:
selection = main_menu_prompt().lower().strip()
selection_words = selection.split()
if selection.startswith("back up"):
if selection_words[-1] == "full_backup":
selection = main_menu_prompt()
action, _, target = selection.rpartition(" ")
if action == "back up":
if target == "all":
backup_all(dotfiles_path, packages_path, fonts_path, configs_path)
git_add_all_commit_push(repo, selection_words[-1])
elif selection_words[-1] == "dotfiles":
git_add_all_commit_push(repo, target)
elif target == "dotfiles":
backup_dotfiles(dotfiles_path)
git_add_all_commit_push(repo, selection_words[-1], separate_dotfiles_repo)
elif selection_words[-1] == "configs":
git_add_all_commit_push(repo, target, separate_dotfiles_repo)
elif target == "configs":
backup_configs(configs_path)
git_add_all_commit_push(repo, selection_words[-1])
elif selection_words[-1] == "packages":
git_add_all_commit_push(repo, target)
elif target == "packages":
backup_packages(packages_path)
git_add_all_commit_push(repo, selection_words[-1])
elif selection_words[-1] == "fonts":
git_add_all_commit_push(repo, target)
elif target == "fonts":
backup_fonts(fonts_path)
git_add_all_commit_push(repo, selection_words[-1])
elif selection.startswith("reinstall"):
if selection_words[-1] == "packages":
git_add_all_commit_push(repo, target)
elif action == "reinstall":
if target == "packages":
reinstall_packages_sb(packages_path)
elif selection_words[-1] == "configs":
elif target == "configs":
reinstall_configs_sb(configs_path)
elif selection_words[-1] == "fonts":
elif target == "fonts":
reinstall_fonts_sb(fonts_path)
elif selection_words[-1] == "dotfiles":
elif target == "dotfiles":
reinstall_dots_sb(dotfiles_path)
elif selection_words[-1] == "full_backup":
elif target == "all":
reinstall_all_sb(dotfiles_path, packages_path, fonts_path, configs_path)
elif selection.endswith("config"):
if selection == "show config":
elif target == "config":
if action.startswith("show"):
show_config()
elif selection == "add path to config":
elif action.startswith("add"):
add_to_config_prompt()
elif selection == "remove path from config":
elif action.startswith("remove"):
remove_from_config_prompt()
elif selection == "destroy backup":
elif action == "destroy":
if prompt_yes_no("Erase backup directory: {}?".format(backup_home_path), Fore.RED):
destroy_backup_dir(backup_home_path)
else:
Expand Down
15 changes: 8 additions & 7 deletions shallow_backup/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,13 @@ def run_cmd_if_no_dry_run(command, dest, dry_run) -> int:
if not dry_run:
overwrite_dir_prompt_if_needed(backup_path, skip)

for mgr in ["brew", "brew cask"]:
# deal with package managers that have spaces in them.
print_pkg_mgr_backup(mgr)
command = f"{mgr} list"
dest = f"{backup_path}/{mgr.replace(' ', '-')}_list.txt"
run_cmd_if_no_dry_run(command, dest, dry_run)
# brew
print_pkg_mgr_backup("brew")
command = f"brew bundle dump --file {backup_path}/brew_list.txt"
dest = f"{backup_path}/brew_list.txt"
if not dry_run:
if not run_cmd(command):
print_yellow("brew package manager not found.")

# ruby
print_pkg_mgr_backup("gem")
Expand All @@ -153,7 +154,7 @@ def run_cmd_if_no_dry_run(command, dest, dry_run) -> int:

# cargo
print_pkg_mgr_backup("cargo")
command = "ls {}".format(home_prefix(".cargo/bin/"))
command = r"cargo install --list | grep '^\w.*:$' | sed -E 's/ v(.*):$/ --version \1/'"
dest = f"{backup_path}/cargo_list.txt"
run_cmd_if_no_dry_run(command, dest, dry_run)

Expand Down
14 changes: 7 additions & 7 deletions shallow_backup/reinstall.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def run_cmd_if_no_dry_run(command, dry_run) -> int:
package_mgrs = set()
for file in os.listdir(packages_path):
manager = file.split("_")[0].replace("-", " ")
if manager in ["gem", "brew-cask", "cargo", "npm", "pip", "pip3", "brew", "vscode", "apm", "macports"]:
if manager in ["gem", "cargo", "npm", "pip", "pip3", "brew", "vscode", "apm", "macports"]:
package_mgrs.add(file.split("_")[0])

print_blue_bold("Package Manager Backups Found:")
Expand All @@ -135,10 +135,9 @@ def run_cmd_if_no_dry_run(command, dry_run) -> int:
# TODO: Multithreading for reinstallation.
# Construct reinstallation commands and execute them
for pm in package_mgrs:
if pm in ["brew", "brew-cask"]:
pm_formatted = pm.replace("-", " ")
print_pkg_mgr_reinstall(pm_formatted)
cmd = f"xargs {pm.replace('-', ' ')} install < {packages_path}/{pm_formatted}_list.txt"
if pm == "brew":
print_pkg_mgr_reinstall(pm)
cmd = f"brew bundle install --no-lock --file {packages_path}/brew_list.txt"
run_cmd_if_no_dry_run(cmd, dry_run)
elif pm == "npm":
print_pkg_mgr_reinstall(pm)
Expand Down Expand Up @@ -169,8 +168,9 @@ def run_cmd_if_no_dry_run(command, dry_run) -> int:
cmd = f"cat {packages_path}/gem_list.txt | xargs -L 1 gem install"
run_cmd_if_no_dry_run(cmd, dry_run)
elif pm == "cargo":
print_red_bold("WARNING: Cargo reinstallation is not possible at the moment.\
\n -> https://github.com/rust-lang/cargo/issues/5593")
print_pkg_mgr_reinstall(pm)
cmd = f"cat {packages_path}/cargo_list.txt | xargs -L 1 cargo install"
run_cmd_if_no_dry_run(cmd, dry_run)

print_section_header("PACKAGE REINSTALLATION COMPLETED", Fore.BLUE)

Expand Down

0 comments on commit b5cc330

Please sign in to comment.