From c9f046f38eae92ec8814cc7136a735d1c45278c6 Mon Sep 17 00:00:00 2001 From: Ivan Malison Date: Fri, 20 Nov 2015 22:54:36 -0800 Subject: [PATCH] imalison python utilities --- dotfiles/lib/python/imalison.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 dotfiles/lib/python/imalison.py diff --git a/dotfiles/lib/python/imalison.py b/dotfiles/lib/python/imalison.py new file mode 100644 index 00000000..515ea09b --- /dev/null +++ b/dotfiles/lib/python/imalison.py @@ -0,0 +1,28 @@ +import os +import errno +from invoke import run + + +def link_filenames(ctx, link_pairs, force=False): + for source, destination in link_pairs: + destination = os.path.expanduser(destination) + source = os.path.expanduser(source) + if force: + ctx.run("sudo rm -rf {0}".format(destination)) + if os.path.exists(destination): + print("Skipping {0} because path already exists".format(destination)) + else: + print("Linking {0} to {1}".format(destination, source)) + ctx.run('ln -s {0} {1}'.format(source, destination)) + + +def ensure_path_exists(path): + try: + os.makedirs(path) + except OSError as exception: + if exception.errno != errno.EEXIST: + raise + + +def command_exists(command, run=run): + return run("hash {0}".format(command), warn=True, hide=True).exited == 0