annotate python/install_config.py @ 408:705dc5cfd68d

make this modular
author Jeff Hammel <jhammel@mozilla.com>
date Sun, 04 Aug 2013 10:31:11 -0700
parents 06fcec56e8fe
children dc64beded724
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
29
8344c7a9847c install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents: 22
diff changeset
22 def execute(*commands):
131
52cf3e146a4c make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
23 """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
24 for command in commands:
8344c7a9847c install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents: 22
diff changeset
25 print ' '.join(command)
8344c7a9847c install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents: 22
diff changeset
26 code = subprocess.call(command)
8344c7a9847c install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents: 22
diff changeset
27 if code:
8344c7a9847c install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents: 22
diff changeset
28 sys.exit(code)
8344c7a9847c install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents: 22
diff changeset
29
408
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
30 class Step(object):
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
31 @classmethod
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
32 def check(cls):
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
33 """checks if the step may be run"""
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
34 def __call__(self):
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
35 execute(*self.commands)
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
36
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
37 class InitializeRepository(Step):
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
38 """make the home directory a repository"""
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
39
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
40 commands = [
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
41 ['hg', 'init'],
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
42 ['hg', 'pull', SRC],
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
43 ['hg', 'update', '-C'],
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
44 ]
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
45
29
8344c7a9847c install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents: 22
diff changeset
46 execute(*commands)
131
52cf3e146a4c make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
47
268
06fcec56e8fe whitespace
Jeff Hammel <jhammel@mozilla.com>
parents: 251
diff changeset
48
218
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
49 # get the which command
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
50 sys.path.append(os.path.join(HOME, 'python'))
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
51 from which import which
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
52
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
53
131
52cf3e146a4c make the install script slightly nicer
Jeff Hammel <jhammel@mozilla.com>
parents: 130
diff changeset
54 # make a (correct) .hg/hgrc file for $HOME
218
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
55 hgrc = """[paths]
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
56 default = http://k0s.org/hg/config
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
57 default-push = ssh://k0s.org/hg/config
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
58 """
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
59 f = file('.hg/hgrc', 'w')
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
60 f.write(hgrc)
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
61 f.close()
1
f58e8e81e16b adding program to install config
k0s <k0scist@gmail.com>
parents:
diff changeset
62
29
8344c7a9847c install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents: 22
diff changeset
63 def install_develop(package):
8344c7a9847c install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents: 22
diff changeset
64 src = 'http://k0s.org/hg/%s' % package
41
eda848575afb chdir to the directory before running python setup.py develop as this seems to be necessary
Jeff Hammel <k0scist@gmail.com>
parents: 36
diff changeset
65 directory = '%s/src/%s' % (package, package)
29
8344c7a9847c install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents: 22
diff changeset
66 commands = [ ['virtualenv/virtualenv.py', package],
44
fc4b830a61e8 * make all subdirectories
Jeff Hammel <k0scist@gmail.com>
parents: 43
diff changeset
67 ['mkdir', '-p', directory ],
fc4b830a61e8 * make all subdirectories
Jeff Hammel <k0scist@gmail.com>
parents: 43
diff changeset
68 ['hg', 'clone', src, directory] ]
29
8344c7a9847c install smartopen by default and some other cleanup (untested)
Jeff Hammel <k0scist@gmail.com>
parents: 22
diff changeset
69 execute(*commands)
41
eda848575afb chdir to the directory before running python setup.py develop as this seems to be necessary
Jeff Hammel <k0scist@gmail.com>
parents: 36
diff changeset
70 old_directory = os.getcwd()
eda848575afb chdir to the directory before running python setup.py develop as this seems to be necessary
Jeff Hammel <k0scist@gmail.com>
parents: 36
diff changeset
71 os.chdir(directory)
eda848575afb chdir to the directory before running python setup.py develop as this seems to be necessary
Jeff Hammel <k0scist@gmail.com>
parents: 36
diff changeset
72 command = ['../../bin/python', 'setup.py', 'develop']
eda848575afb chdir to the directory before running python setup.py develop as this seems to be necessary
Jeff Hammel <k0scist@gmail.com>
parents: 36
diff changeset
73 execute(command)
eda848575afb chdir to the directory before running python setup.py develop as this seems to be necessary
Jeff Hammel <k0scist@gmail.com>
parents: 36
diff changeset
74 os.chdir(old_directory)
218
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
75
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
76 # do git stuff
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
77 git = which('git')
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
78 if git:
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
79 # get virtual env
219
4390ca34912c use new virtualenv repo
Jeff Hammel <jhammel@mozilla.com>
parents: 218
diff changeset
80 virtualenv_commands = [['git', 'clone', 'https://github.com/pypa/virtualenv.git'],
218
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
81 ['ln', '-s', HOME + '/virtualenv/virtualenv.py', HOME + '/bin/']]
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
82 execute(*virtualenv_commands)
6
524f9e7fa224 be backwards compatible
k0s <k0scist@gmail.com>
parents: 1
diff changeset
83
218
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
84 # setup git's global ignore, since git is silly about this
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
85 # and doesn't look for the file in the right place
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
86 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
87
218
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
88 # install some python
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
89 install_develop('smartopen')
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
90 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
91
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
92 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
93 ['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
94 ]
e4221e45d6c1 update install script
Jeff Hammel <jhammel@mozilla.com>
parents: 174
diff changeset
95 execute(*postinstall_commands)
234
761e7dfc675e updates from most recent usage
Jeff Hammel <jhammel@mozilla.com>
parents: 219
diff changeset
96 else:
761e7dfc675e updates from most recent usage
Jeff Hammel <jhammel@mozilla.com>
parents: 219
diff changeset
97 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
98
36
d83f35b9b799 adding xclip package and echo which packages need installation
Jeff Hammel <k0scist@gmail.com>
parents: 34
diff changeset
99 # - ubuntu packages to install:
408
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
100 PACKAGES=["mercurial", "unison", "fluxbox", "antiword", "xclip",
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
101 "graphviz", "python-dev", "python-lxml", "curl", "arandr",
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
102 "git", "emacs", "irssi"]
43
Jeff Hammel <k0scist@gmail.com>
parents: 42
diff changeset
103 print "Ensure the following packages are installed:"
408
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
104 print "sudo apt-get install %s" % ' '.join(PACKAGES)
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
105
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
106 def main(args=sys.argv[1:]):
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
107 usage = '%prog [options]'
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
108 parser = optparse.OptionParser(usage=usage, description=__doc__)
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
109 options, args = parser.parse_args()
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
110
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
111 steps = [InitializeRepository]
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
112
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
113 if __name__ == '__main__':
705dc5cfd68d make this modular
Jeff Hammel <jhammel@mozilla.com>
parents: 268
diff changeset
114 main()