Mercurial > hg > config
annotate python/install_config.py @ 410:ffa08f0de165
fix a thing
author | Jeff Hammel <jhammel@mozilla.com> |
---|---|
date | Sun, 04 Aug 2013 15:14:16 -0700 |
parents | dc64beded724 |
children | 9d6e7a471fc7 |
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 |
76 commands = [ | |
77 ['hg', 'init'], | |
78 ['hg', 'pull', SRC], | |
79 ['hg', 'update', '-C'], | |
80 ] | |
81 | |
29
8344c7a9847c
install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents:
22
diff
changeset
|
82 execute(*commands) |
131
52cf3e146a4c
make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents:
130
diff
changeset
|
83 |
268 | 84 |
131
52cf3e146a4c
make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents:
130
diff
changeset
|
85 # make a (correct) .hg/hgrc file for $HOME |
218 | 86 hgrc = """[paths] |
87 default = http://k0s.org/hg/config | |
88 default-push = ssh://k0s.org/hg/config | |
89 """ | |
90 f = file('.hg/hgrc', 'w') | |
91 f.write(hgrc) | |
92 f.close() | |
1 | 93 |
410 | 94 # get the which command |
95 sys.path.append(os.path.join(HOME, 'python')) | |
96 from which import which | |
409 | 97 |
218 | 98 |
99 # do git stuff | |
100 git = which('git') | |
101 if git: | |
102 # get virtual env | |
219 | 103 virtualenv_commands = [['git', 'clone', 'https://github.com/pypa/virtualenv.git'], |
218 | 104 ['ln', '-s', HOME + '/virtualenv/virtualenv.py', HOME + '/bin/']] |
105 execute(*virtualenv_commands) | |
6 | 106 |
218 | 107 # setup git's global ignore, since git is silly about this |
108 # and doesn't look for the file in the right place | |
109 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
|
110 |
218 | 111 # install some python |
112 install_develop('smartopen') | |
113 install_develop('silvermirror') # XXX this won't actually work since python-dev isn't installed; install it first | |
114 | |
115 postinstall_commands = [ ['ln', '-s', os.path.join(HOME, 'smartopen', 'bin', 'smartopen'), os.path.join(HOME, 'bin', 'smartopen') ], | |
116 ['ln', '-s', os.path.join(HOME, 'silvermirror', 'bin', 'silvermirror'), os.path.join(HOME, 'bin', 'silvermirror') ], | |
117 ] | |
118 execute(*postinstall_commands) | |
234
761e7dfc675e
updates from most recent usage
Jeff Hammel <jhammel@mozilla.com>
parents:
219
diff
changeset
|
119 else: |
761e7dfc675e
updates from most recent usage
Jeff Hammel <jhammel@mozilla.com>
parents:
219
diff
changeset
|
120 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
|
121 |
36
d83f35b9b799
adding xclip package and echo which packages need installation
Jeff Hammel <k0scist@gmail.com>
parents:
34
diff
changeset
|
122 # - ubuntu packages to install: |
408 | 123 PACKAGES=["mercurial", "unison", "fluxbox", "antiword", "xclip", |
124 "graphviz", "python-dev", "python-lxml", "curl", "arandr", | |
125 "git", "emacs", "irssi"] | |
43 | 126 print "Ensure the following packages are installed:" |
408 | 127 print "sudo apt-get install %s" % ' '.join(PACKAGES) |
128 | |
129 def main(args=sys.argv[1:]): | |
130 usage = '%prog [options]' | |
131 parser = optparse.OptionParser(usage=usage, description=__doc__) | |
132 options, args = parser.parse_args() | |
409 | 133 return |
408 | 134 |
135 steps = [InitializeRepository] | |
409 | 136 for step in steps: |
137 | |
138 | |
408 | 139 if __name__ == '__main__': |
140 main() |