annotate python/install_config.py @ 428:59e6c8115a97

.gitconfig
author Jeff Hammel <jhammel@mozilla.com>
date Tue, 06 Aug 2013 23:08:42 -0700
parents be90af6dfd47
children 9b9b66c2c1fc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
f58e8e81e16b adding program to install config
k0s <k0scist@gmail.com>
parents:
diff changeset
1 #!/usr/bin/env python
234
761e7dfc675e updates from most recent usage
Jeff Hammel <jhammel@mozilla.com>
parents: 219
diff changeset
2
1
f58e8e81e16b adding program to install config
k0s <k0scist@gmail.com>
parents:
diff changeset
3 """
f58e8e81e16b adding program to install config
k0s <k0scist@gmail.com>
parents:
diff changeset
4 installs config to a user's home directory
f58e8e81e16b adding program to install config
k0s <k0scist@gmail.com>
parents:
diff changeset
5 this can be done with
16
57298ea7a7f1 fix string for how to install
k0s <k0scist@gmail.com>
parents: 14
diff changeset
6 curl http://k0s.org/hg/config/raw-file/tip/python/install_config.py | python
1
f58e8e81e16b adding program to install config
k0s <k0scist@gmail.com>
parents:
diff changeset
7 """
f58e8e81e16b adding program to install config
k0s <k0scist@gmail.com>
parents:
diff changeset
8
218
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
9 import imp
408
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
10 import optparse
1
f58e8e81e16b adding program to install config
k0s <k0scist@gmail.com>
parents:
diff changeset
11 import os
131
52cf3e146a4c make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
12 import subprocess
6
524f9e7fa224 be backwards compatible
k0s <k0scist@gmail.com>
parents: 1
diff changeset
13 import sys
131
52cf3e146a4c make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
14
408
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
15 # config repository
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
16 SRC='http://k0s.org/hg/config'
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
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
f58e8e81e16b adding program to install config
k0s <k0scist@gmail.com>
parents:
diff changeset
21
410
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
22 ### standalone functions
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
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
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
32 def install_develop(package):
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
33 """install k0s.ware for development"""
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
34
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
35 src = 'http://k0s.org/hg/%s' % package
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
36 directory = '%s/src/%s' % (package, package)
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
37 commands = [ ['virtualenv/virtualenv.py', package],
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
38 ['mkdir', '-p', directory ],
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
39 ['hg', 'clone', src, directory] ]
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
40 execute(*commands)
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
41 old_directory = os.getcwd()
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
42 os.chdir(directory)
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
43 command = ['../../bin/python', 'setup.py', 'develop']
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
44 execute(command)
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
45 os.chdir(old_directory)
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
46
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
47
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
48 ### process steps
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
49
408
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
50 class Step(object):
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
51 @classmethod
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
52 def check(cls):
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
53 """checks if the step may be run"""
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
54 def __call__(self):
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
55 execute(*self.commands)
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
56
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
57 class InitializeRepository(Step):
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
58 """make the home directory a repository"""
409
dc64beded724 pt deux and such
Jeff Hammel <jhammel@mozilla.com>
parents: 408
diff changeset
59 commands = [
dc64beded724 pt deux and such
Jeff Hammel <jhammel@mozilla.com>
parents: 408
diff changeset
60 ['hg', 'init'],
dc64beded724 pt deux and such
Jeff Hammel <jhammel@mozilla.com>
parents: 408
diff changeset
61 ['hg', 'pull', SRC],
dc64beded724 pt deux and such
Jeff Hammel <jhammel@mozilla.com>
parents: 408
diff changeset
62 ['hg', 'update', '-C'],
dc64beded724 pt deux and such
Jeff Hammel <jhammel@mozilla.com>
parents: 408
diff changeset
63 ]
410
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
64 @classmethd
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
65 def write_hgrc(self):
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
66 hgrc = """[paths]
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
67 default = http://k0s.org/hg/config
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
68 default-push = ssh://k0s.org/hg/config
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
69 """
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
70 with file('.hg/hgrc', 'w') as f
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
71 f.write(hgrc)
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
72 def __call__(self):
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
73 Step.__call__(self)
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
74 self.write_hgrc()
408
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
75
411
Jeff Hammel <jhammel@mozilla.com>
parents: 410
diff changeset
76 #
Jeff Hammel <jhammel@mozilla.com>
parents: 410
diff changeset
77 #
Jeff Hammel <jhammel@mozilla.com>
parents: 410
diff changeset
78 #@requires(Command('git'))
Jeff Hammel <jhammel@mozilla.com>
parents: 410
diff changeset
79 #class GitInstall
Jeff Hammel <jhammel@mozilla.com>
parents: 410
diff changeset
80
Jeff Hammel <jhammel@mozilla.com>
parents: 410
diff changeset
81 ### legacy -v
Jeff Hammel <jhammel@mozilla.com>
parents: 410
diff changeset
82
408
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
83 commands = [
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
84 ['hg', 'init'],
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
85 ['hg', 'pull', SRC],
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
86 ['hg', 'update', '-C'],
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
87 ]
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
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
06fcec56e8fe whitespace
Jeff Hammel <jhammel@mozilla.com>
parents: 251
diff changeset
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
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
93 hgrc = """[paths]
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
94 default = http://k0s.org/hg/config
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
95 default-push = ssh://k0s.org/hg/config
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
96 """
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
97 f = file('.hg/hgrc', 'w')
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
98 f.write(hgrc)
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
99 f.close()
1
f58e8e81e16b adding program to install config
k0s <k0scist@gmail.com>
parents:
diff changeset
100
410
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
101 # get the which command
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
102 sys.path.append(os.path.join(HOME, 'python'))
ffa08f0de165 fix a thing
Jeff Hammel <jhammel@mozilla.com>
parents: 409
diff changeset
103 from which import which
409
dc64beded724 pt deux and such
Jeff Hammel <jhammel@mozilla.com>
parents: 408
diff changeset
104
218
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
105
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
106 # do git stuff
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
107 git = which('git')
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
108 if git:
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
109 # get virtual env
219
4390ca34912c use new virtualenv repo
Jeff Hammel <jhammel@mozilla.com>
parents: 218
diff changeset
110 virtualenv_commands = [['git', 'clone', 'https://github.com/pypa/virtualenv.git'],
218
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
111 ['ln', '-s', HOME + '/virtualenv/virtualenv.py', HOME + '/bin/']]
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
112 execute(*virtualenv_commands)
6
524f9e7fa224 be backwards compatible
k0s <k0scist@gmail.com>
parents: 1
diff changeset
113
218
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
114 # setup git's global ignore, since git is silly about this
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
115 # and doesn't look for the file in the right place
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
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
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
118 # install some python
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
119 install_develop('smartopen')
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
120 install_develop('silvermirror') # XXX this won't actually work since python-dev isn't installed; install it first
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
121
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
122 postinstall_commands = [ ['ln', '-s', os.path.join(HOME, 'smartopen', 'bin', 'smartopen'), os.path.join(HOME, 'bin', 'smartopen') ],
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
123 ['ln', '-s', os.path.join(HOME, 'silvermirror', 'bin', 'silvermirror'), os.path.join(HOME, 'bin', 'silvermirror') ],
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
124 ]
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
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
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
130 PACKAGES=["mercurial", "unison", "fluxbox", "antiword", "xclip",
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
131 "graphviz", "python-dev", "python-lxml", "curl", "arandr",
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
132 "git", "emacs", "irssi"]
43
Jeff Hammel <k0scist@gmail.com>
parents: 42
diff changeset
133 print "Ensure the following packages are installed:"
408
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
134 print "sudo apt-get install %s" % ' '.join(PACKAGES)
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
135
427
Jeff Hammel <jhammel@mozilla.com>
parents: 416
diff changeset
136 # TODO:
Jeff Hammel <jhammel@mozilla.com>
parents: 416
diff changeset
137 # - dl and get ~/web/sync.ini :
Jeff Hammel <jhammel@mozilla.com>
parents: 416
diff changeset
138 # ln -s /home/jhammel/web/sync.ini /home/jhammel/.silvermirror
Jeff Hammel <jhammel@mozilla.com>
parents: 416
diff changeset
139 # - handle cases where config is autogenerated BUT you still want
Jeff Hammel <jhammel@mozilla.com>
parents: 416
diff changeset
140 # to have some base (e.g. .gkrellm2/user_config)
416
Jeff Hammel <jhammel@mozilla.com>
parents: 411
diff changeset
141
408
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
142 def main(args=sys.argv[1:]):
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
143 usage = '%prog [options]'
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
144 parser = optparse.OptionParser(usage=usage, description=__doc__)
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
145 options, args = parser.parse_args()
409
dc64beded724 pt deux and such
Jeff Hammel <jhammel@mozilla.com>
parents: 408
diff changeset
146 return
408
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
147
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
148 steps = [InitializeRepository]
409
dc64beded724 pt deux and such
Jeff Hammel <jhammel@mozilla.com>
parents: 408
diff changeset
149 for step in steps:
416
Jeff Hammel <jhammel@mozilla.com>
parents: 411
diff changeset
150 pass # TODO
Jeff Hammel <jhammel@mozilla.com>
parents: 411
diff changeset
151
408
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
152 if __name__ == '__main__':
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
153 main()