Mercurial > hg > config
annotate python/install_config.py @ 579:f894bd779943
STUB: python/install_config.py
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Mon, 20 Jan 2014 19:19:10 -0800 |
parents | c16238544fca |
children | b563a9c1f2b7 |
rev | line source |
---|---|
1 | 1 #!/usr/bin/env python |
234
761e7dfc675e
updates from most recent usage
Jeff Hammel <jhammel@mozilla.com>
parents:
219
diff
changeset
|
2 |
1 | 3 """ |
4 installs config to a user's home directory | |
5 this can be done with | |
16 | 6 curl http://k0s.org/hg/config/raw-file/tip/python/install_config.py | python |
1 | 7 """ |
8 | |
579
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
9 # TODO: |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
10 # - dl and get ~/web/sync.ini : |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
11 # ln -s /home/jhammel/web/sync.ini /home/jhammel/.silvermirror |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
12 # - handle cases where config is autogenerated BUT you still want |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
13 # to have some base (e.g. .gkrellm2/user_config) |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
14 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
15 # imports |
218 | 16 import imp |
408 | 17 import optparse |
1 | 18 import os |
131
52cf3e146a4c
make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents:
130
diff
changeset
|
19 import subprocess |
6 | 20 import sys |
131
52cf3e146a4c
make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents:
130
diff
changeset
|
21 |
579
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
22 # globals |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
23 SRC='http://k0s.org/hg/config' # config repository |
14
ac34d580c6d7
make symbolic links when necessary (should generalize)
k0s <k0scist@gmail.com>
parents:
7
diff
changeset
|
24 HOME=os.environ['HOME'] |
1 | 25 |
410 | 26 ### standalone functions |
27 | |
29
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
28 def execute(*commands): |
131
52cf3e146a4c
make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents:
130
diff
changeset
|
29 """execute a series of commands""" |
29
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
30 for command in commands: |
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
31 print ' '.join(command) |
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
32 code = subprocess.call(command) |
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
33 if code: |
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
34 sys.exit(code) |
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
35 |
410 | 36 def install_develop(package): |
37 """install k0s.ware for development""" | |
38 | |
39 src = 'http://k0s.org/hg/%s' % package | |
40 directory = '%s/src/%s' % (package, package) | |
41 commands = [ ['virtualenv/virtualenv.py', package], | |
42 ['mkdir', '-p', directory ], | |
43 ['hg', 'clone', src, directory] ] | |
44 execute(*commands) | |
45 old_directory = os.getcwd() | |
46 os.chdir(directory) | |
47 command = ['../../bin/python', 'setup.py', 'develop'] | |
48 execute(command) | |
49 os.chdir(old_directory) | |
50 | |
51 | |
52 ### process steps | |
53 | |
408 | 54 class Step(object): |
55 @classmethod | |
56 def check(cls): | |
57 """checks if the step may be run""" | |
58 def __call__(self): | |
59 execute(*self.commands) | |
60 | |
61 class InitializeRepository(Step): | |
62 """make the home directory a repository""" | |
409 | 63 commands = [ |
64 ['hg', 'init'], | |
65 ['hg', 'pull', SRC], | |
66 ['hg', 'update', '-C'], | |
67 ] | |
577 | 68 @classmethod |
410 | 69 def write_hgrc(self): |
70 hgrc = """[paths] | |
71 default = http://k0s.org/hg/config | |
72 default-push = ssh://k0s.org/hg/config | |
73 """ | |
577 | 74 with file('.hg/hgrc', 'w') as f: |
410 | 75 f.write(hgrc) |
76 def __call__(self): | |
77 Step.__call__(self) | |
78 self.write_hgrc() | |
408 | 79 |
579
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
80 |
411 | 81 #@requires(Command('git')) |
82 #class GitInstall | |
577 | 83 |
578 | 84 class UbuntuPackages(Step): |
85 """ubuntu packages to install""" | |
86 | |
579
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
87 PACKAGES=["mercurial", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
88 "unison", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
89 "fluxbox", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
90 "antiword", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
91 "xclip", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
92 "graphviz", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
93 "python-dev", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
94 "python-lxml", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
95 "curl", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
96 "arandr", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
97 "git", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
98 "emacs", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
99 "irssi"] |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
100 def __call__(self): |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
101 print "Ensure the following packages are installed:" |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
102 print "sudo apt-get install %s" % ' '.join(PACKAGES) |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
103 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
104 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
105 ### legacy -v- |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
106 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
107 def legacy(): |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
108 """legacy : TO DEPRECATE!""" |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
109 commands = [ |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
110 ['hg', 'init'], |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
111 ['hg', 'pull', SRC], |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
112 ['hg', 'update', '-C'], |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
113 ] |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
114 os.chdir(HOME) # go home |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
115 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
116 execute(*commands) |
408 | 117 |
579
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
118 # make a (correct) .hg/hgrc file for $HOME |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
119 hgrc = """[paths] |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
120 default = http://k0s.org/hg/config |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
121 default-push = ssh://k0s.org/hg/config |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
122 """ |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
123 with file(os.path.join(HOME, '.hg/hgrc', 'w')) as f: |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
124 f.write(hgrc) |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
125 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
126 # get the which command |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
127 sys.path.append(os.path.join(HOME, 'python')) |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
128 from which import which |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
129 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
130 # do git stuff |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
131 git = which('git') |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
132 if git: |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
133 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
134 # get virtual env |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
135 virtualenv_commands = [['git', 'clone', 'https://github.com/pypa/virtualenv.git'], |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
136 ['ln', '-s', HOME + '/virtualenv/virtualenv.py', HOME + '/bin/']] |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
137 execute(*virtualenv_commands) |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
138 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
139 # setup git's global ignore, since git is silly about this |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
140 # and doesn't look for the file in the right place |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
141 execute(['git', 'config', '--global', 'core.excludesfile', os.path.join(HOME, '.gitignore')]) |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
142 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
143 # install some python |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
144 install_develop('smartopen') |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
145 install_develop('silvermirror') # XXX this won't actually work since python-dev isn't installed; install it first |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
146 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
147 postinstall_commands = [['ln', '-s', os.path.join(HOME, 'smartopen', 'bin', 'smartopen'), os.path.join(HOME, 'bin', 'smartopen') ], |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
148 ['ln', '-s', os.path.join(HOME, 'silvermirror', 'bin', 'silvermirror'), os.path.join(HOME, 'bin', 'silvermirror') ], |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
149 ] |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
150 execute(*postinstall_commands) |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
151 else: |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
152 print "git not installed" |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
153 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
154 |
416 | 155 |
408 | 156 def main(args=sys.argv[1:]): |
578 | 157 |
158 # go home | |
159 os.chdir(HOME) | |
160 | |
161 # parse command line | |
408 | 162 usage = '%prog [options]' |
163 parser = optparse.OptionParser(usage=usage, description=__doc__) | |
578 | 164 parser.add_option('--deb', '--dpkg', '--debian-packages', |
165 dest='debian_packages', | |
166 action='store_true', default=False, | |
167 help="display debian packages to install") | |
579
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
168 parser.add_option('-l', '--list', '--list-steps', |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
169 dest='list_steps', |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
170 action='store_true', default=False, |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
171 help="list steps to be run") |
408 | 172 options, args = parser.parse_args() |
173 | |
578 | 174 # plan steps |
579
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
175 steps = [InitializeRepository, UbuntuPackages] |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
176 if options.debian_packages: |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
177 steps = [DebianPackages] |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
178 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
179 if options.list_steps: |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
180 # list steps if specified |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
181 for step in steps: |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
182 print step |
578 | 183 |
184 # execute steps | |
409 | 185 for step in steps: |
579
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
186 instance = step() |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
187 instance() |
416 | 188 |
408 | 189 if __name__ == '__main__': |
190 main() |