#!/usr/bin/env python import os import sys import yaml # Colors for terminal from termcolor import colored # Path of dotfiles homepath = '/home/urbain' dotpath = homepath + '/dotfiles' # Load yaml configuration file with open(dotpath + "/install.yaml", 'r') as stream: config = yaml.load(stream) # Special and default symlinks special_symlinks = set(config['special'].keys()) normal_symlinks = set(config['default']) def perform(action): for f in special_symlinks | normal_symlinks: # Print filename print('[' + colored(f, 'green') + ']') if f in config['pre'] and action == 'up': # Format command command = config['pre'][f] formatted = command.format(file=f, path=dotpath) # Print & execute print(formatted) os.system(formatted) # Target of symlink if f in special_symlinks: t = config['special'][f] elif f in normal_symlinks: t = homepath + '/' + f # Command to execute command = config['commands'][action] formatted = command.format(file=f, path=dotpath, target=t) # Print & execute command print(formatted) os.system(formatted) print('\n') perform(sys.argv[1])