Skip to content

Commit

Permalink
Merge df3710b into b14140d
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-coutinho committed Dec 26, 2020
2 parents b14140d + df3710b commit edee3bb
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
19 changes: 13 additions & 6 deletions shallow_backup/backup.py
Expand Up @@ -138,12 +138,19 @@ 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", "gem"]:
# 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)
# ruby
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.")

# cargo
print_pkg_mgr_backup("cargo")
Expand Down
9 changes: 4 additions & 5 deletions shallow_backup/reinstall.py
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

0 comments on commit edee3bb

Please sign in to comment.