2014-10-21 12:00:04 -06:00
|
|
|
import errno
|
2014-10-10 05:00:19 -06:00
|
|
|
import os
|
|
|
|
|
|
|
|
from invoke import run
|
|
|
|
|
|
|
|
|
2016-10-08 23:18:26 -06:00
|
|
|
TASKS_DIRECTORY = os.path.dirname(__file__)
|
|
|
|
REPO_DIRECTORY = os.path.dirname(TASKS_DIRECTORY)
|
2014-10-10 05:00:19 -06:00
|
|
|
DOTFILES_DIRECTORY = os.path.join(REPO_DIRECTORY, 'dotfiles')
|
|
|
|
RESOURCES_DIRECTORY = os.path.join(REPO_DIRECTORY, 'resources')
|
|
|
|
|
|
|
|
|
|
|
|
def command_exists(command, run=run):
|
|
|
|
return run("hash {0}".format(command), warn=True, hide=True).exited == 0
|
2014-10-21 12:00:04 -06:00
|
|
|
|
|
|
|
|
2015-06-15 05:57:01 -06:00
|
|
|
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))
|
|
|
|
|
|
|
|
|
2014-10-21 12:00:04 -06:00
|
|
|
def ensure_path_exists(path):
|
|
|
|
try:
|
|
|
|
os.makedirs(path)
|
|
|
|
except OSError as exception:
|
|
|
|
if exception.errno != errno.EEXIST:
|
|
|
|
raise
|