Skip to content

Commit

Permalink
Update homebrew support
Browse files Browse the repository at this point in the history
  • Loading branch information
tim-coutinho committed Dec 25, 2020
1 parent dd765f7 commit 50df4e8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 6 deletions.
11 changes: 10 additions & 1 deletion shallow_backup/backup.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,22 @@ 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"]:
for mgr in ["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)

# 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:
ret = run_cmd(command)
if not ret:
print_yellow("Package manager not present.")

# cargo
print_pkg_mgr_backup("cargo")
command = "ls {}".format(home_prefix(".cargo/bin/"))
Expand Down
9 changes: 4 additions & 5 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

0 comments on commit 50df4e8

Please sign in to comment.