Mercurial > hg > config
annotate python/install_config.py @ 438:364ddd44fd82
all the parts are there; now just to assemble it
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Thu, 08 Aug 2013 17:00:47 -0700 |
parents | be90af6dfd47 |
children | 9b9b66c2c1fc |
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 | |
218 | 9 import imp |
408 | 10 import optparse |
1 | 11 import os |
131
52cf3e146a4c
make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents:
130
diff
changeset
|
12 import subprocess |
6 | 13 import sys |
131
52cf3e146a4c
make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents:
130
diff
changeset
|
14 |
408 | 15 # config repository |
16 SRC='http://k0s.org/hg/config' | |
17 | |
131
52cf3e146a4c
make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents:
130
diff
changeset
|
18 # go home |
14
ac34d580c6d7
make symbolic links when necessary (should generalize)
k0s <k0scist@gmail.com>
parents:
7
diff
changeset
|
19 HOME=os.environ['HOME'] |
ac34d580c6d7
make symbolic links when necessary (should generalize)
k0s <k0scist@gmail.com>
parents:
7
diff
changeset
|
20 os.chdir(HOME) |
1 | 21 |
410 | 22 ### standalone functions |
23 | |
29
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
24 def execute(*commands): |
131
52cf3e146a4c
make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents:
130
diff
changeset
|
25 """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
|
26 for command in commands: |
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
27 print ' '.join(command) |
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
28 code = subprocess.call(command) |
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
29 if code: |
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
30 sys.exit(code) |
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
31 |
410 | 32 def install_develop(package): |
33 """install k0s.ware for development""" | |
34 | |
35 src = 'http://k0s.org/hg/%s' % package | |
36 directory = '%s/src/%s' % (package, package) | |
37 commands = [ ['virtualenv/virtualenv.py', package], | |
38 ['mkdir', '-p', directory ], | |
39 ['hg', 'clone', src, directory] ] | |
40 execute(*commands) | |
41 old_directory = os.getcwd() | |
42 os.chdir(directory) | |
43 command = ['../../bin/python', 'setup.py', 'develop'] | |
44 execute(command) | |
45 os.chdir(old_directory) | |
46 | |
47 | |
48 ### process steps | |
49 | |
408 | 50 class Step(object): |
51 @classmethod | |
52 def check(cls): | |
53 """checks if the step may be run""" | |
54 def __call__(self): | |
55 execute(*self.commands) | |
56 | |
57 class InitializeRepository(Step): | |
58 """make the home directory a repository""" | |
409 | 59 commands = [ |
60 ['hg', 'init'], | |
61 ['hg', 'pull', SRC], | |
62 ['hg', 'update', '-C'], | |
63 ] | |
410 | 64 @classmethd |
65 def write_hgrc(self): | |
66 hgrc = """[paths] | |
67 default = http://k0s.org/hg/config | |
68 default-push = ssh://k0s.org/hg/config | |
69 """ | |
70 with file('.hg/hgrc', 'w') as f | |
71 f.write(hgrc) | |
72 def __call__(self): | |
73 Step.__call__(self) | |
74 self.write_hgrc() | |
408 | 75 |
411 | 76 # |
77 # | |
78 #@requires(Command('git')) | |
79 #class GitInstall | |
80 | |
81 ### legacy -v | |
82 | |
408 | 83 commands = [ |
84 ['hg', 'init'], | |
85 ['hg', 'pull', SRC], | |
86 ['hg', 'update', '-C'], | |
87 ] | |
88 | |
29
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
89 execute(*commands) |
131
52cf3e146a4c
make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents:
130
diff
changeset
|
90 |
268 | 91 |
131
52cf3e146a4c
make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents:
130
diff
changeset
|
92 # make a (correct) .hg/hgrc file for $HOME |
218 | 93 hgrc = """[paths] |
94 default = http://k0s.org/hg/config | |
95 default-push = ssh://k0s.org/hg/config | |
96 """ | |
97 f = file('.hg/hgrc', 'w') | |
98 f.write(hgrc) | |
99 f.close() | |
1 | 100 |
410 | 101 # get the which command |
102 sys.path.append(os.path.join(HOME, 'python')) | |
103 from which import which | |
409 | 104 |
218 | 105 |
106 # do git stuff | |
107 git = which('git') | |
108 if git: | |
109 # get virtual env | |
219 | 110 virtualenv_commands = [['git', 'clone', 'https://github.com/pypa/virtualenv.git'], |
218 | 111 ['ln', '-s', HOME + '/virtualenv/virtualenv.py', HOME + '/bin/']] |
112 execute(*virtualenv_commands) | |
6 | 113 |
218 | 114 # setup git's global ignore, since git is silly about this |
115 # and doesn't look for the file in the right place | |
116 execute(['git', 'config', '--global', 'core.excludesfile', os.path.join(HOME, '.gitignore')]) | |
32
f878d9f62211
fix syntax error and actually execute the commands
Jeff Hammel <k0scist@gmail.com>
parents:
31
diff
changeset
|
117 |
218 | 118 # install some python |
119 install_develop('smartopen') | |
120 install_develop('silvermirror') # XXX this won't actually work since python-dev isn't installed; install it first | |
121 | |
122 postinstall_commands = [ ['ln', '-s', os.path.join(HOME, 'smartopen', 'bin', 'smartopen'), os.path.join(HOME, 'bin', 'smartopen') ], | |
123 ['ln', '-s', os.path.join(HOME, 'silvermirror', 'bin', 'silvermirror'), os.path.join(HOME, 'bin', 'silvermirror') ], | |
124 ] | |
125 execute(*postinstall_commands) | |
234
761e7dfc675e
updates from most recent usage
Jeff Hammel <jhammel@mozilla.com>
parents:
219
diff
changeset
|
126 else: |
761e7dfc675e
updates from most recent usage
Jeff Hammel <jhammel@mozilla.com>
parents:
219
diff
changeset
|
127 print "git not installed" |
45
069a739d88ad
get fluxbox menu from a webpage, i.e. http://k0s.org/programs.html
Jeff Hammel <k0scist@gmail.com>
parents:
43
diff
changeset
|
128 |
36
d83f35b9b799
adding xclip package and echo which packages need installation
Jeff Hammel <k0scist@gmail.com>
parents:
34
diff
changeset
|
129 # - ubuntu packages to install: |
408 | 130 PACKAGES=["mercurial", "unison", "fluxbox", "antiword", "xclip", |
131 "graphviz", "python-dev", "python-lxml", "curl", "arandr", | |
132 "git", "emacs", "irssi"] | |
43 | 133 print "Ensure the following packages are installed:" |
408 | 134 print "sudo apt-get install %s" % ' '.join(PACKAGES) |
135 | |
427 | 136 # TODO: |
137 # - dl and get ~/web/sync.ini : | |
138 # ln -s /home/jhammel/web/sync.ini /home/jhammel/.silvermirror | |
139 # - handle cases where config is autogenerated BUT you still want | |
140 # to have some base (e.g. .gkrellm2/user_config) | |
416 | 141 |
408 | 142 def main(args=sys.argv[1:]): |
143 usage = '%prog [options]' | |
144 parser = optparse.OptionParser(usage=usage, description=__doc__) | |
145 options, args = parser.parse_args() | |
409 | 146 return |
408 | 147 |
148 steps = [InitializeRepository] | |
409 | 149 for step in steps: |
416 | 150 pass # TODO |
151 | |
408 | 152 if __name__ == '__main__': |
153 main() |