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