-
Notifications
You must be signed in to change notification settings - Fork 20
/
fabfile.py
63 lines (57 loc) · 2.17 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
"""Some random fabric tasks to make my life easier.
"""
from fabric.api import run
from fabric.api import env
from fabric.api import local
from fabric.utils import abort
from fabric.contrib.files import exists
env.dotfiles = 'git://github.com/claytron/dotfiles'
env.dotfiles_local = "$HOME/.dotfiles"
def push_dotfiles(rsync=None, dry=None, port=None):
"""Push my dotfiles to a specific server
rsync::
If this option is passed, do an rsync instead of trying to
check out from svn.
dry::
Pass the dry-run option to rsync
"""
# run this to expose potential issues with the machine like
# bash not being in /bin/bash
run("echo $HOME")
if not exists("$HOME"):
abort("You do not appear to have a home directory")
# Only bail out if we are doing a checkout
if rsync is None and exists(".dotfiles"):
abort("The .dotfiles directory already exists")
if rsync is None:
run('git clone %s .dotfiles' % env.dotfiles)
else:
options = []
if dry is not None:
options.append('-n')
if port is not None:
options.append("--port=%s" % port)
# rsync to the host deleting files that don't exist here
# TODO: use built-in fabric command?
# NOTE: I still use svn as the main repo, so ignore git
local('rsync %s -av --delete --exclude=".git" %s/ %s:.dotfiles' % (
' '.join(options), env.dotfiles_local, env.host_string))
run('.dotfiles/create_links.sh remove')
run('.dotfiles/create_links.sh')
def remove_dotfiles(ignore=None):
"""Remove my dotfiles from a specific server
"""
# run this to expose potential issues with the machine like
# bash not being in /bin/bash
run("echo $HOME")
if not exists("$HOME"):
abort("You do not appear to have a home directory")
if not exists(".dotfiles"):
abort("The .dotfiles directory does not exist")
output = run("svn st .dotfiles")
msg = "There are local changes, commit or revert before continuing"
if output and ignore is None:
abort(msg)
run('git status .dotfiles')
run('.dotfiles/create_links.sh cleanup')
run('rm -rf .dotfiles')