Mercurial > hg > config
comparison python/install_config.py @ 408:705dc5cfd68d
make this modular
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sun, 04 Aug 2013 10:31:11 -0700 |
parents | 06fcec56e8fe |
children | dc64beded724 |
comparison
equal
deleted
inserted
replaced
407:a8982ae84a9b | 408:705dc5cfd68d |
---|---|
4 installs config to a user's home directory | 4 installs config to a user's home directory |
5 this can be done with | 5 this can be done with |
6 curl http://k0s.org/hg/config/raw-file/tip/python/install_config.py | python | 6 curl http://k0s.org/hg/config/raw-file/tip/python/install_config.py | python |
7 """ | 7 """ |
8 | 8 |
9 SRC='http://k0s.org/hg/config' | |
10 | |
11 import imp | 9 import imp |
10 import optparse | |
12 import os | 11 import os |
13 import subprocess | 12 import subprocess |
14 import sys | 13 import sys |
15 | 14 |
15 # config repository | |
16 SRC='http://k0s.org/hg/config' | |
17 | |
16 # go home | 18 # go home |
17 HOME=os.environ['HOME'] | 19 HOME=os.environ['HOME'] |
18 os.chdir(HOME) | 20 os.chdir(HOME) |
19 | |
20 commands = [ # make the home directory a repository | |
21 ['hg', 'init'], | |
22 ['hg', 'pull', SRC], | |
23 ['hg', 'update', '-C'], | |
24 ] | |
25 | 21 |
26 def execute(*commands): | 22 def execute(*commands): |
27 """execute a series of commands""" | 23 """execute a series of commands""" |
28 for command in commands: | 24 for command in commands: |
29 print ' '.join(command) | 25 print ' '.join(command) |
30 code = subprocess.call(command) | 26 code = subprocess.call(command) |
31 if code: | 27 if code: |
32 sys.exit(code) | 28 sys.exit(code) |
29 | |
30 class Step(object): | |
31 @classmethod | |
32 def check(cls): | |
33 """checks if the step may be run""" | |
34 def __call__(self): | |
35 execute(*self.commands) | |
36 | |
37 class InitializeRepository(Step): | |
38 """make the home directory a repository""" | |
39 | |
40 commands = [ | |
41 ['hg', 'init'], | |
42 ['hg', 'pull', SRC], | |
43 ['hg', 'update', '-C'], | |
44 ] | |
33 | 45 |
34 execute(*commands) | 46 execute(*commands) |
35 | 47 |
36 | 48 |
37 # get the which command | 49 # get the which command |
83 execute(*postinstall_commands) | 95 execute(*postinstall_commands) |
84 else: | 96 else: |
85 print "git not installed" | 97 print "git not installed" |
86 | 98 |
87 # - ubuntu packages to install: | 99 # - ubuntu packages to install: |
88 PACKAGES="mercurial unison fluxbox antiword xclip graphviz python-dev python-lxml curl arandr git emacs irssi" | 100 PACKAGES=["mercurial", "unison", "fluxbox", "antiword", "xclip", |
101 "graphviz", "python-dev", "python-lxml", "curl", "arandr", | |
102 "git", "emacs", "irssi"] | |
89 print "Ensure the following packages are installed:" | 103 print "Ensure the following packages are installed:" |
90 print "sudo apt-get install %s" % PACKAGES | 104 print "sudo apt-get install %s" % ' '.join(PACKAGES) |
105 | |
106 def main(args=sys.argv[1:]): | |
107 usage = '%prog [options]' | |
108 parser = optparse.OptionParser(usage=usage, description=__doc__) | |
109 options, args = parser.parse_args() | |
110 | |
111 steps = [InitializeRepository] | |
112 | |
113 if __name__ == '__main__': | |
114 main() |