meta: add install/uninstall system
This commit is contained in:
39
meta/uninstall.py
Normal file
39
meta/uninstall.py
Normal file
@@ -0,0 +1,39 @@
|
||||
import sys
|
||||
import os
|
||||
import json
|
||||
import pathlib
|
||||
|
||||
dotfile_dir = sys.argv[1]
|
||||
home_dir = str(pathlib.Path.home())
|
||||
|
||||
def uninstall_component(comp):
|
||||
print('Uninstalling component: {}...'.format(comp['name']))
|
||||
comp_dir = os.path.join(dotfile_dir, comp['name'])
|
||||
|
||||
if 'link-files' in comp:
|
||||
link_files = comp['link-files']
|
||||
for f in link_files:
|
||||
source_path = os.path.join(comp_dir, f['source'])
|
||||
dest_path = os.path.join(home_dir, f['dest'])
|
||||
if os.path.exists(dest_path):
|
||||
print(' removing link {}'.format(dest_path))
|
||||
os.unlink(dest_path)
|
||||
|
||||
if 'link-dirs' in comp:
|
||||
link_dirs = comp['link-dirs']
|
||||
for f in link_dirs:
|
||||
source_path = os.path.join(comp_dir, f['source'])
|
||||
dest_path = os.path.join(home_dir, f['dest'])
|
||||
if not os.path.exists(dest_path):
|
||||
print(' removing link {} -> {}'.format(dest_path))
|
||||
os.unlink(dest_path)
|
||||
|
||||
|
||||
components_path = os.path.join(dotfile_dir, 'meta', 'components.json')
|
||||
components = None
|
||||
|
||||
with open(components_path, 'r') as f:
|
||||
components = json.load(f)
|
||||
|
||||
for comp in components:
|
||||
uninstall_component(comp)
|
||||
Reference in New Issue
Block a user