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