-
Notifications
You must be signed in to change notification settings - Fork 0
/
uninstall.py
executable file
·32 lines (28 loc) · 1.32 KB
/
uninstall.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/usr/bin/env python
# https://github.com/anishathalye/dotbot/wiki/Tips-and-Tricks#uninstall-script
import yaml
import os
import logging
import glob
logging.basicConfig()
logging.getLogger().setLevel(logging.INFO)
dotfile_groups = os.getenv("DOTFILE_GROUPS")
groups = dotfile_groups.split(",") if dotfile_groups else None
if groups and len(groups) > 0:
logging.info(f"""Remove links from {", ".join(map(lambda f: f"{f}.yml", groups))}.""")
for group in groups:
stream = open(f"{group}.yml", "r")
conf = yaml.load(stream, yaml.FullLoader)
for section in conf:
if "link" in section:
for target in section["link"]:
realpath = os.path.expanduser(target)
logging.debug(f"Checking path: {realpath}")
if os.path.islink(realpath):
logging.info(f"Removing link: {realpath}")
os.unlink(realpath)
else:
logging.warning("No groups found. Set DOTFILE_GROUPS environment variable to uninstall.")
available_config_files = filter(lambda f: f if f not in ["uninstall.yml"] else None, glob.glob("*.yml"))
available_dotfile_groups = ", ".join(map(lambda f: os.path.splitext(f)[0], available_config_files))
logging.info(F"Available DOTFILE_GROUPS: {available_dotfile_groups}.")