2014-10-10 05:00:19 -06:00
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
|
|
|
|
from invoke import Collection, ctask
|
|
|
|
|
|
|
|
from . import osx
|
|
|
|
from . import linux
|
|
|
|
from .util import DOTFILES_DIRECTORY, RESOURCES_DIRECTORY
|
|
|
|
|
|
|
|
|
|
|
|
ns = Collection()
|
|
|
|
ns.add_collection(osx)
|
|
|
|
ns.add_collection(linux)
|
|
|
|
|
|
|
|
|
|
|
|
@ctask(default=True)
|
|
|
|
def setup(ctx):
|
|
|
|
ctx.config['run']['pty'] = False
|
|
|
|
ctx.config['run']['warn'] = True
|
2014-12-15 04:43:47 -07:00
|
|
|
dotfiles(ctx, 'f')
|
2014-10-10 05:00:19 -06:00
|
|
|
if 'darwin' in sys.platform:
|
2014-11-12 03:03:43 -07:00
|
|
|
osx.setup(ctx)
|
2014-10-10 05:00:19 -06:00
|
|
|
else:
|
2014-11-12 03:03:43 -07:00
|
|
|
linux.setup(ctx)
|
2014-12-22 03:44:06 -07:00
|
|
|
fix_pip_download_cache(ctx)
|
2014-12-31 10:51:24 -07:00
|
|
|
python(ctx)
|
2014-11-07 06:11:23 -07:00
|
|
|
powerline(ctx)
|
2014-10-22 21:59:51 -06:00
|
|
|
install_npm_libraries(ctx)
|
2014-10-10 17:22:15 -06:00
|
|
|
change_shell(ctx)
|
2014-10-10 05:00:19 -06:00
|
|
|
|
|
|
|
|
|
|
|
@ctask
|
2014-10-22 21:59:51 -06:00
|
|
|
def dotfiles(ctx, flags=''):
|
2014-10-10 05:00:19 -06:00
|
|
|
ctx.run('hash dotfiles || sudo pip install dotfiles')
|
2014-10-10 05:35:51 -06:00
|
|
|
return ctx.run('dotfiles -s{1} -R {0}'.format(DOTFILES_DIRECTORY, flags))
|
2014-10-10 05:00:19 -06:00
|
|
|
|
|
|
|
|
2014-11-22 06:09:53 -07:00
|
|
|
@ctask
|
|
|
|
def dropbox_dotfiles(ctx, flags='f'):
|
|
|
|
ctx.run('hash dotfiles || sudo pip install dotfiles')
|
|
|
|
ctx.run('dotfiles -s{1} -R {0}'.format(
|
|
|
|
os.path.join(
|
|
|
|
os.path.expanduser('~'), 'Dropbox', 'configs', 'dotfiles'
|
|
|
|
),
|
|
|
|
flags
|
|
|
|
))
|
2014-12-15 17:50:58 -07:00
|
|
|
link_filenames(ctx, [('~/Dropbox/configs/custom.el', '~/.emacs.d/custom.el')], force=True)
|
|
|
|
|
2014-11-22 06:09:53 -07:00
|
|
|
|
2014-11-07 06:11:23 -07:00
|
|
|
@ctask
|
|
|
|
def powerline(ctx):
|
2014-11-10 18:30:34 -07:00
|
|
|
ctx.run('sudo pip install psutil')
|
2014-11-10 04:37:59 -07:00
|
|
|
ctx.run('sudo pip install git+git://github.com/Lokaltog/powerline')
|
2014-11-07 06:11:23 -07:00
|
|
|
|
|
|
|
|
2014-10-10 05:00:19 -06:00
|
|
|
@ctask
|
2014-12-31 10:51:24 -07:00
|
|
|
def python(ctx):
|
2014-11-10 04:37:59 -07:00
|
|
|
ctx.run('sudo pip install setuptools --upgrade')
|
2014-10-10 05:00:19 -06:00
|
|
|
ctx.run('sudo pip install -r {0}'.format(
|
|
|
|
os.path.join(RESOURCES_DIRECTORY, 'requirements.txt')
|
|
|
|
))
|
|
|
|
|
2014-10-10 16:56:34 -06:00
|
|
|
|
2014-10-10 05:00:19 -06:00
|
|
|
@ctask
|
|
|
|
def install_npm_libraries(ctx):
|
|
|
|
ctx.run('source {0}'.format(
|
|
|
|
os.path.join(RESOURCES_DIRECTORY, 'npm.sh')
|
|
|
|
))
|
|
|
|
|
|
|
|
|
|
|
|
@ctask
|
|
|
|
def vimstall(ctx):
|
|
|
|
ctx.run('vim +BundleInstall! +q +q')
|
|
|
|
|
|
|
|
|
2014-10-10 17:22:15 -06:00
|
|
|
@ctask
|
|
|
|
def change_shell(ctx):
|
|
|
|
ctx.run('sudo chsh -s $(which zsh) $(whoami)')
|
|
|
|
|
|
|
|
|
2014-11-21 03:56:16 -07:00
|
|
|
@ctask
|
2014-12-15 17:50:58 -07:00
|
|
|
def link_dropbox_other(ctx, force=False):
|
2014-11-21 03:56:16 -07:00
|
|
|
link_pairs = (
|
|
|
|
('~/Dropbox/Documents', '~/Documents'),
|
2014-12-06 13:48:06 -07:00
|
|
|
('~/Dropbox/Pictures', '~/Pictures'),
|
2014-12-15 18:28:56 -07:00
|
|
|
('~/Dropbox/org', '~/org'),
|
2014-12-15 17:50:58 -07:00
|
|
|
('~/Dropbox/Desktop', '~/Desktop')
|
2014-11-21 03:56:16 -07:00
|
|
|
)
|
2014-12-15 17:50:58 -07:00
|
|
|
link_filenames(ctx, link_pairs, force)
|
|
|
|
|
|
|
|
|
2014-12-15 18:21:21 -07:00
|
|
|
def link_filenames(ctx, link_pairs, force=False):
|
2014-11-21 03:56:16 -07:00
|
|
|
for source, destination in link_pairs:
|
|
|
|
destination = os.path.expanduser(destination)
|
|
|
|
source = os.path.expanduser(source)
|
2014-12-15 17:50:58 -07:00
|
|
|
if force:
|
|
|
|
ctx.run("sudo rm -rf {0}".format(destination))
|
2014-11-21 03:56:16 -07:00
|
|
|
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-11-10 00:31:06 -07:00
|
|
|
@ctask
|
|
|
|
def customize_user_settings(ctx):
|
|
|
|
input_function = input if sys.version_info.major == 3 else raw_input
|
2014-11-10 04:37:59 -07:00
|
|
|
username = input_function("Enter the user's full name: ")
|
|
|
|
email = input_function("Enter the user's email address: ")
|
|
|
|
with open(os.path.expanduser('~/.gitconfig.custom'), 'w') as custom_file:
|
2014-11-10 00:31:06 -07:00
|
|
|
custom_file.write("""[user]
|
|
|
|
name = {0}
|
|
|
|
email = {1}""".format(username, email))
|
|
|
|
|
|
|
|
|
2014-12-21 05:04:35 -07:00
|
|
|
@ctask
|
|
|
|
def fix_pip_download_cache(ctx):
|
|
|
|
ctx.run("sudo chown imalison ~/.pip/download_cache -R")
|
|
|
|
|
|
|
|
|
|
|
|
ns.add_task(fix_pip_download_cache)
|
2014-10-10 17:22:15 -06:00
|
|
|
ns.add_task(change_shell)
|
2014-11-10 00:31:06 -07:00
|
|
|
ns.add_task(customize_user_settings)
|
2014-10-10 05:00:19 -06:00
|
|
|
ns.add_task(dotfiles)
|
2014-12-15 18:21:21 -07:00
|
|
|
ns.add_task(dropbox_dotfiles)
|
2014-10-22 21:59:51 -06:00
|
|
|
ns.add_task(install_npm_libraries)
|
2014-12-31 10:51:24 -07:00
|
|
|
ns.add_task(python)
|
2014-12-15 18:21:21 -07:00
|
|
|
ns.add_task(link_dropbox_other)
|
2014-11-07 06:11:23 -07:00
|
|
|
ns.add_task(powerline)
|
2014-11-10 00:31:06 -07:00
|
|
|
ns.add_task(setup)
|
|
|
|
ns.add_task(vimstall)
|