Mercurial > hg > config
annotate python/install_config.py @ 590:e93b81d8a586
STUB: python/install_config.py
author | Jeff Hammel <k0scist@gmail.com> |
---|---|
date | Fri, 24 Jan 2014 17:53:23 -0800 |
parents | ed99a36df540 |
children | 542d329835ec |
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 |
590
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
23 SRC = 'http://k0s.org/hg/config' # config repository |
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
24 HOME = os.environ['HOME'] # home directory |
1 | 25 |
410 | 26 ### standalone functions |
27 | |
590
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
28 def execute(*commands, **kwargs): |
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: |
590
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
31 print (subprocess.list2cmdline(' '.join(command)) |
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
32 code = subprocess.call(command, **kwargs) |
29
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
33 |
410 | 34 def install_develop(package): |
35 """install k0s.ware for development""" | |
36 | |
37 src = 'http://k0s.org/hg/%s' % package | |
38 directory = '%s/src/%s' % (package, package) | |
590
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
39 commands = [['virtualenv/virtualenv.py', package], |
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
40 ['mkdir', '-p', directory ], |
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
41 ['hg', 'clone', src, directory] ] |
410 | 42 execute(*commands) |
43 old_directory = os.getcwd() | |
44 os.chdir(directory) | |
45 command = ['../../bin/python', 'setup.py', 'develop'] | |
46 execute(command) | |
47 os.chdir(old_directory) | |
48 | |
584 | 49 ### generic step framework |
410 | 50 |
590
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
51 |
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
52 |
408 | 53 class Step(object): |
54 @classmethod | |
55 def check(cls): | |
56 """checks if the step may be run""" | |
584 | 57 @classmethod |
58 def name(cls): | |
59 return cls.__name__ | |
60 __str__ = name | |
408 | 61 def __call__(self): |
62 execute(*self.commands) | |
63 | |
584 | 64 class Command(object): |
65 """require a command""" | |
66 | |
67 ### process steps | |
68 | |
408 | 69 class InitializeRepository(Step): |
70 """make the home directory a repository""" | |
409 | 71 commands = [ |
72 ['hg', 'init'], | |
73 ['hg', 'pull', SRC], | |
74 ['hg', 'update', '-C'], | |
75 ] | |
577 | 76 @classmethod |
410 | 77 def write_hgrc(self): |
584 | 78 """make a (correct) .hg/hgrc file for $HOME""" |
79 | |
410 | 80 hgrc = """[paths] |
81 default = http://k0s.org/hg/config | |
82 default-push = ssh://k0s.org/hg/config | |
83 """ | |
577 | 84 with file('.hg/hgrc', 'w') as f: |
410 | 85 f.write(hgrc) |
86 def __call__(self): | |
87 Step.__call__(self) | |
88 self.write_hgrc() | |
408 | 89 |
584 | 90 # get the which command |
91 sys.path.append(os.path.join(HOME, 'python')) | |
92 from which import which | |
579
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
93 |
411 | 94 #@requires(Command('git')) |
590
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
95 class ConfigureGit(Step): |
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
96 """configure git""" |
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
97 commands = [['git', 'config', '--global', 'core.excludesfile', os.path.join(HOME, '.gitignore')]] |
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
98 |
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
99 #@requires(Command('git')) |
584 | 100 class InstallVirtualenv(Step): |
101 commands = [['git', 'clone', 'https://github.com/pypa/virtualenv.git'], | |
590
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
102 ['ln', '-s', |
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
103 os.path.join(HOME, 'virtualenv/virtualenv.py'), |
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
104 os.path.join(HOME, 'bin', 'virtualenv.py')] |
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
105 ] |
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
106 |
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
107 class InstallKWare(Step): |
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
108 """install k0s.ware""" |
577 | 109 |
582 | 110 class DebianPackages(Step): |
578 | 111 """ubuntu packages to install""" |
584 | 112 # TODO: actually install packages |
578 | 113 |
579
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
114 PACKAGES=["mercurial", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
115 "unison", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
116 "fluxbox", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
117 "antiword", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
118 "xclip", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
119 "graphviz", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
120 "python-dev", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
121 "python-lxml", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
122 "curl", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
123 "arandr", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
124 "git", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
125 "emacs", |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
126 "irssi"] |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
127 def __call__(self): |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
128 print "Ensure the following packages are installed:" |
582 | 129 print "sudo apt-get install %s" % ' '.join(self.PACKAGES) |
590
e93b81d8a586
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
584
diff
changeset
|
130 |
579
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
131 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
132 ### legacy -v- |
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 def legacy(): |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
135 """legacy : TO DEPRECATE!""" |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
136 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
137 # do git stuff |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
138 git = which('git') |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
139 if git: |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
140 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
141 # 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
|
142 # 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
|
143 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
144 # install some python |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
145 install_develop('smartopen') |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
146 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
|
147 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
148 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
|
149 ['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
|
150 ] |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
151 execute(*postinstall_commands) |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
152 else: |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
153 print "git not installed" |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
154 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
155 |
582 | 156 ### CLI |
416 | 157 |
408 | 158 def main(args=sys.argv[1:]): |
578 | 159 |
160 # go home | |
161 os.chdir(HOME) | |
162 | |
163 # parse command line | |
408 | 164 usage = '%prog [options]' |
165 parser = optparse.OptionParser(usage=usage, description=__doc__) | |
578 | 166 parser.add_option('--deb', '--dpkg', '--debian-packages', |
167 dest='debian_packages', | |
168 action='store_true', default=False, | |
169 help="display debian packages to install") | |
579
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
170 parser.add_option('-l', '--list', '--list-steps', |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
171 dest='list_steps', |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
172 action='store_true', default=False, |
580
b563a9c1f2b7
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
579
diff
changeset
|
173 help="list steps to be run and exit") |
408 | 174 options, args = parser.parse_args() |
175 | |
578 | 176 # plan steps |
582 | 177 steps = [InitializeRepository, DebianPackages] |
579
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
178 if options.debian_packages: |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
179 steps = [DebianPackages] |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
180 |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
181 if options.list_steps: |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
182 # list steps if specified |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
183 for step in steps: |
584 | 184 print(step.name()) |
580
b563a9c1f2b7
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
579
diff
changeset
|
185 parser.exit() |
578 | 186 |
187 # execute steps | |
409 | 188 for step in steps: |
579
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
189 instance = step() |
f894bd779943
STUB: python/install_config.py
Jeff Hammel <k0scist@gmail.com>
parents:
578
diff
changeset
|
190 instance() |
416 | 191 |
408 | 192 if __name__ == '__main__': |
193 main() |