From 2dc9d4299442280e9e2b386de66507edc3d7b681 Mon Sep 17 00:00:00 2001 From: Urbain Vaes Date: Fri, 15 Jan 2016 10:08:00 +0000 Subject: Simplify install script --- bin/dot | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100755 bin/dot (limited to 'bin') diff --git a/bin/dot b/bin/dot new file mode 100755 index 0000000..905e0c1 --- /dev/null +++ b/bin/dot @@ -0,0 +1,58 @@ +#!/usr/bin/env python + +import os +import sys +import yaml + +# Colors for terminal +from termcolor import colored + + +# Path of dotfiles +dotpath = '/home/urbain/dotfiles' + +# Load yaml configuration file +with open(dotpath + "/install.yaml", 'r') as stream: + config = yaml.load(stream) + +# Special symlinks +special_symlinks = set(config['special'].keys()) + +# All files in dir +normal_symlinks = set(os.listdir(dotpath)) - set(config['exclude']) + + +def perform(action): + + # Command to execute + command = config['commands'][action] + + for f in special_symlinks | normal_symlinks: + + # Print filename + print('[' + colored(f, 'green') + ']') + + if f in config['pre']: + print(config['pre'][f]) + os.system(config['pre'][f]) + + # Target of symlink + if f in special_symlinks: + t = config['special'][f] + elif f in normal_symlinks: + t = config['default'].format(file=f) + + if t != "": + # Formatted command + formatted = command.format(file=f, path=dotpath, target=t) + + # Print & execute command + print(formatted) + os.system(formatted) + + else: + print("Nothing to do!") + + print('\n') + +perform(sys.argv[1]) -- cgit v1.2.3