dotfiles/tasks/__init__.py

136 lines
3.5 KiB
Python
Raw Normal View History

import os
import sys
2016-07-09 01:47:56 -06:00
from invoke import Collection, task as ctask
2016-09-03 18:38:47 -06:00
from . import arch
from . import linux
2016-09-03 18:38:47 -06:00
from . import osx
2015-06-15 05:57:01 -06:00
from .util import DOTFILES_DIRECTORY, RESOURCES_DIRECTORY, link_filenames
ns = Collection()
ns.add_collection(osx)
ns.add_collection(linux)
2016-09-03 18:38:47 -06:00
ns.add_collection(arch)
@ctask(default=True)
def setup(ctx):
ctx.config['run']['pty'] = False
ctx.config['run']['warn'] = True
if 'darwin' in sys.platform:
osx.setup(ctx)
else:
linux.setup(ctx)
2016-10-08 23:18:26 -06:00
dotfiles(ctx)
2014-12-31 10:51:24 -07:00
python(ctx)
2016-10-08 23:18:26 -06:00
fix_pip(ctx)
2014-10-22 21:59:51 -06:00
install_npm_libraries(ctx)
2014-10-10 17:22:15 -06:00
change_shell(ctx)
@ctask
def dotfiles(ctx, flags=''):
ctx.run('hash dotfiles || sudo pip install dotfiles')
return ctx.run('dotfiles -s{1} -R {0}'.format(DOTFILES_DIRECTORY, flags))
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
))
2015-03-08 01:37:04 -07:00
2015-04-28 14:42:55 -06:00
2015-03-08 01:37:04 -07:00
@ctask
def link_emacs(ctx, flags='f'):
2015-04-28 14:42:55 -06:00
link_filenames(ctx, [('~/Dropbox/configs/custom-before.el', '~/.emacs.d/custom-before.el'),
# ('~/Dropbox/configs/elpa', '~/.emacs.d/elpa'),
('~/Dropbox/configs/custom-after.el', '~/.emacs.d/custom-after.el')],
force=True)
2014-12-15 17:50:58 -07:00
2014-11-22 06:09:53 -07:00
@ctask
2014-12-31 10:51:24 -07:00
def python(ctx):
2016-10-08 23:18:26 -06:00
ctx.run('pyenv install 2.7.11')
ctx.run('pyenv global 2.7.11')
ctx.run('pip install setuptools --upgrade')
ctx.run('pip install -r {0}'.format(
os.path.join(RESOURCES_DIRECTORY, 'requirements.txt')
))
2014-10-10 16:56:34 -06:00
@ctask
def install_npm_libraries(ctx):
ctx.run('source {0}'.format(
os.path.join(RESOURCES_DIRECTORY, 'npm.sh')
))
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'),
('~/Dropbox/org', '~/org'),
2015-01-02 09:22:24 -07:00
('~/Dropbox/Desktop', '~/Desktop'),
('~/Dropbox/ebooks', '~/ebooks'),
2014-11-21 03:56:16 -07:00
)
2014-12-15 17:50:58 -07:00
link_filenames(ctx, link_pairs, force)
@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:
custom_file.write("""[user]
name = {0}
2015-01-26 01:42:29 -07:00
email = {1}""".format(username, email))
2014-12-21 05:04:35 -07:00
@ctask
def fix_pip(ctx):
ctx.run("sudo easy_install -U pip")
ctx.run("sudo chown $(whoami) ~/.pip/download_cache -R")
2014-12-21 05:04:35 -07:00
2015-01-21 23:10:58 -07:00
@ctask
def fix_dropbox_permissions(ctx):
ctx.run("sudo chown -R $(whoami) ~/.ssh")
ctx.run("sudo chown -R $(whoami) $(readlink -f ~/.ssh)")
ctx.run("sudo chmod -R 700 ~/.ssh")
ctx.run("sudo chmod -R 700 $(readlink -f ~/.ssh)")
2015-01-22 14:49:10 -07:00
ctx.run("sudo chmod -R 700 ~/Dropbox/auth/foolery.pem")
2015-01-26 01:42:29 -07:00
ctx.run("sudo chmod -R 700 ~/Dropbox/configs/dotfiles/gnupg")
2015-01-21 23:10:58 -07:00
2016-09-13 03:06:15 -06:00
@ctask
def cabal_for_emacs(ctx):
ctx.run("cabal install happy hasktags stylish-haskell present ghc-mod hlint hoogle structured-haskell-mode hindent")
ns.add_task(fix_pip)
2014-10-10 17:22:15 -06:00
ns.add_task(change_shell)
ns.add_task(customize_user_settings)
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)
ns.add_task(setup)
2015-01-21 23:10:58 -07:00
ns.add_task(fix_dropbox_permissions)
2015-04-28 14:42:55 -06:00
ns.add_task(link_emacs)