Skip to content

Commit

Permalink
Add VSCode backup/reinstall, including extensions and pip3 backup/rei…
Browse files Browse the repository at this point in the history
…nstall. (#205)

Close #211, #212 and #45.
  • Loading branch information
AlexanderProd authored and alichtman committed Jan 7, 2019
1 parent 9f8f9d4 commit b907c83
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 1 deletion.
3 changes: 3 additions & 0 deletions README.md
Expand Up @@ -90,6 +90,7 @@ By default, `shallow-backup` backs these up.

2. App Config Files
* Atom
* VSCode
* Sublime Text 2/3
* Terminal.app

Expand All @@ -99,8 +100,10 @@ By default, `shallow-backup` backs these up.
* `cargo`
* `gem`
* `pip`
* `pip3`
* `npm`
* `macports`
* `VSCode` Extensions
* `Sublime Text 2/3` Packages
* System Applications

Expand Down
12 changes: 12 additions & 0 deletions shallow_backup/backup.py
Expand Up @@ -116,6 +116,12 @@ def backup_packages(backup_path, skip=False):
dest = "{}/pip_list.txt".format(backup_path)
run_cmd_write_stdout(command, dest)

# pip3
print_pkg_mgr_backup("pip3")
command = "pip3 list --format=freeze"
dest = "{}/pip3_list.txt".format(backup_path)
run_cmd_write_stdout(command, dest)

# npm
print_pkg_mgr_backup("npm")
command = "npm ls --global --parseable=true --depth=0"
Expand All @@ -137,6 +143,12 @@ def backup_packages(backup_path, skip=False):
dest = "{}/apm_list.txt".format(backup_path)
run_cmd_write_stdout(command, dest)

# vscode extensions
print_pkg_mgr_backup("VSCode")
command = "code --list-extensions --show-versions"
dest = "{}/vscode_list.txt".format(backup_path)
run_cmd_write_stdout(command, dest)

# macports
print_pkg_mgr_backup("macports")
command = "port installed requested"
Expand Down
12 changes: 12 additions & 0 deletions shallow_backup/compatibility.py
Expand Up @@ -17,23 +17,35 @@ def get_config_paths():
if "darwin" == get_os_name():
sublime2_path = os.path.join(get_home(), "Library/Application Support/Sublime Text 2")
sublime3_path = os.path.join(get_home(), "Library/Application Support/Sublime Text 3")
vscode_path_1 = os.path.join(get_home(), "Library/Application Support/Code/User/settings.json")
vscode_path_2 = os.path.join(get_home(), "Library/Application Support/Code/User/Snippets")
vscode_path_3 = os.path.join(get_home(), "Library/Application Support/Code/User/keybindings.json")
atom_path = os.path.join(get_home(), ".atom")
terminal_path = os.path.join(get_home(), "Library/Preferences/com.apple.Terminal.plist")

return {
sublime2_path: "sublime2",
sublime3_path: "sublime3",
vscode_path_1: "vscode/settings",
vscode_path_2: "vscode/Snippets",
vscode_path_3: "vscode/keybindings",
atom_path: "atom",
terminal_path: "terminal_plist"
}
else:
sublime2_path = "/.config/sublime-text-2"
sublime3_path = "/.config/sublime-text-3"
vscode_path_1 = "/.config/Code/User/settings.json"
vscode_path_2 = "/.config/Code/User/Snippets"
vscode_path_3 = "/.config/Code/User/keybindings.json"
atom_path = os.path.join(get_home(), ".atom")
return {
# TODO: Double check these paths. Not sure these are right.
sublime2_path: "sublime2",
sublime3_path: "sublime3",
vscode_path_1: "vscode/settings",
vscode_path_2: "vscode/Snippets",
vscode_path_3: "vscode/keybindings",
atom_path: "atom"
}

Expand Down
1 change: 1 addition & 0 deletions shallow_backup/config.py
Expand Up @@ -52,6 +52,7 @@ def get_default_config():
"default-gitignore": [
"dotfiles/.ssh",
"dotfiles/.pypirc",
".DS_Store"
],
"config_mapping" : get_config_paths()
}
Expand Down
12 changes: 11 additions & 1 deletion shallow_backup/reinstall.py
Expand Up @@ -73,7 +73,7 @@ def reinstall_packages_sb(packages_path):
package_mgrs = set()
for file in os.listdir(packages_path):
manager = file.split("_")[0].replace("-", " ")
if manager in ["gem", "brew-cask", "cargo", "npm", "pip", "brew", "apm", "macports"]:
if manager in ["gem", "brew-cask", "cargo", "npm", "pip", "pip3", "brew", "vscode", "apm", "macports"]:
package_mgrs.add(file.split("_")[0])

print_blue_bold("Package Manager Backups Found:")
Expand All @@ -97,6 +97,16 @@ def reinstall_packages_sb(packages_path):
print_pkg_mgr_reinstall(pm)
cmd = "pip install -r {0}/pip_list.txt".format(packages_path)
run_cmd(cmd)
elif pm == "pip3":
print_pkg_mgr_reinstall(pm)
cmd = "pip3 install -r {0}/pip3_list.txt".format(packages_path)
run_cmd(cmd)
elif pm == "vscode":
print_pkg_mgr_reinstall(pm)
with open("{0}/vscode_list.txt".format(packages_path), "r") as f:
for x in f:
cmd = "code --install-extension {0}".format(x)
run_cmd(cmd)
elif pm == "apm":
print_pkg_mgr_reinstall(pm)
cmd = "apm install --packages-file {0}/apm_list.txt".format(packages_path)
Expand Down

0 comments on commit b907c83

Please sign in to comment.