From dbd87d78faab7ae7608ff8f7552c2f6ac4f33f74 Mon Sep 17 00:00:00 2001 From: Tim Coutinho Date: Tue, 20 Jul 2021 22:15:54 -0700 Subject: [PATCH] Update homebrew support (#294) Closes #218 Co-authored-by: Aaron Lichtman --- shallow_backup/backup.py | 19 +++++++++++++------ shallow_backup/reinstall.py | 9 ++++----- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/shallow_backup/backup.py b/shallow_backup/backup.py index 1db8739c..af7f6cba 100644 --- a/shallow_backup/backup.py +++ b/shallow_backup/backup.py @@ -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("gem") + command = "gem list" + dest = f"{backup_path}/gem_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") diff --git a/shallow_backup/reinstall.py b/shallow_backup/reinstall.py index c35fe3a6..b822a7f6 100644 --- a/shallow_backup/reinstall.py +++ b/shallow_backup/reinstall.py @@ -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:") @@ -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)