Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions shallow_backup/backup.py
Original file line number Diff line number Diff line change
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("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")
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