comparison python/install_config.py @ 579:f894bd779943

STUB: python/install_config.py
author Jeff Hammel <k0scist@gmail.com>
date Mon, 20 Jan 2014 19:19:10 -0800
parents c16238544fca
children b563a9c1f2b7
comparison
equal deleted inserted replaced
578:c16238544fca 579:f894bd779943
4 installs config to a user's home directory 4 installs config to a user's home directory
5 this can be done with 5 this can be done with
6 curl http://k0s.org/hg/config/raw-file/tip/python/install_config.py | python 6 curl http://k0s.org/hg/config/raw-file/tip/python/install_config.py | python
7 """ 7 """
8 8
9 # TODO:
10 # - dl and get ~/web/sync.ini :
11 # ln -s /home/jhammel/web/sync.ini /home/jhammel/.silvermirror
12 # - handle cases where config is autogenerated BUT you still want
13 # to have some base (e.g. .gkrellm2/user_config)
14
15 # imports
9 import imp 16 import imp
10 import optparse 17 import optparse
11 import os 18 import os
12 import subprocess 19 import subprocess
13 import sys 20 import sys
14 21
15 # config repository 22 # globals
16 SRC='http://k0s.org/hg/config' 23 SRC='http://k0s.org/hg/config' # config repository
17 HOME=os.environ['HOME'] 24 HOME=os.environ['HOME']
18 25
19 ### standalone functions 26 ### standalone functions
20 27
21 def execute(*commands): 28 def execute(*commands):
68 f.write(hgrc) 75 f.write(hgrc)
69 def __call__(self): 76 def __call__(self):
70 Step.__call__(self) 77 Step.__call__(self)
71 self.write_hgrc() 78 self.write_hgrc()
72 79
73 # 80
74 #
75 #@requires(Command('git')) 81 #@requires(Command('git'))
76 #class GitInstall 82 #class GitInstall
77
78 ### legacy -v
79
80 commands = [
81 ['hg', 'init'],
82 ['hg', 'pull', SRC],
83 ['hg', 'update', '-C'],
84 ]
85
86 os.chdir(HOME) # go home
87
88 execute(*commands)
89
90 # make a (correct) .hg/hgrc file for $HOME
91 hgrc = """[paths]
92 default = http://k0s.org/hg/config
93 default-push = ssh://k0s.org/hg/config
94 """
95 with file(os.path.join(HOME, '.hg/hgrc', 'w')) as f:
96 f.write(hgrc)
97
98 # get the which command
99 sys.path.append(os.path.join(HOME, 'python'))
100 from which import which
101
102
103 # do git stuff
104 git = which('git')
105 if git:
106 # get virtual env
107 virtualenv_commands = [['git', 'clone', 'https://github.com/pypa/virtualenv.git'],
108 ['ln', '-s', HOME + '/virtualenv/virtualenv.py', HOME + '/bin/']]
109 execute(*virtualenv_commands)
110
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')])
114
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)
123 else:
124 print "git not installed"
125 83
126 class UbuntuPackages(Step): 84 class UbuntuPackages(Step):
127 """ubuntu packages to install""" 85 """ubuntu packages to install"""
128 86
129 PACKAGES=["mercurial", "unison", "fluxbox", "antiword", "xclip", 87 PACKAGES=["mercurial",
130 "graphviz", "python-dev", "python-lxml", "curl", "arandr", 88 "unison",
131 "git", "emacs", "irssi"] 89 "fluxbox",
132 print "Ensure the following packages are installed:" 90 "antiword",
133 print "sudo apt-get install %s" % ' '.join(PACKAGES) 91 "xclip",
92 "graphviz",
93 "python-dev",
94 "python-lxml",
95 "curl",
96 "arandr",
97 "git",
98 "emacs",
99 "irssi"]
100 def __call__(self):
101 print "Ensure the following packages are installed:"
102 print "sudo apt-get install %s" % ' '.join(PACKAGES)
134 103
135 # TODO: 104
136 # - dl and get ~/web/sync.ini : 105 ### legacy -v-
137 # ln -s /home/jhammel/web/sync.ini /home/jhammel/.silvermirror 106
138 # - handle cases where config is autogenerated BUT you still want 107 def legacy():
139 # to have some base (e.g. .gkrellm2/user_config) 108 """legacy : TO DEPRECATE!"""
109 commands = [
110 ['hg', 'init'],
111 ['hg', 'pull', SRC],
112 ['hg', 'update', '-C'],
113 ]
114 os.chdir(HOME) # go home
115
116 execute(*commands)
117
118 # make a (correct) .hg/hgrc file for $HOME
119 hgrc = """[paths]
120 default = http://k0s.org/hg/config
121 default-push = ssh://k0s.org/hg/config
122 """
123 with file(os.path.join(HOME, '.hg/hgrc', 'w')) as f:
124 f.write(hgrc)
125
126 # get the which command
127 sys.path.append(os.path.join(HOME, 'python'))
128 from which import which
129
130 # do git stuff
131 git = which('git')
132 if git:
133
134 # get virtual env
135 virtualenv_commands = [['git', 'clone', 'https://github.com/pypa/virtualenv.git'],
136 ['ln', '-s', HOME + '/virtualenv/virtualenv.py', HOME + '/bin/']]
137 execute(*virtualenv_commands)
138
139 # setup git's global ignore, since git is silly about this
140 # and doesn't look for the file in the right place
141 execute(['git', 'config', '--global', 'core.excludesfile', os.path.join(HOME, '.gitignore')])
142
143 # install some python
144 install_develop('smartopen')
145 install_develop('silvermirror') # XXX this won't actually work since python-dev isn't installed; install it first
146
147 postinstall_commands = [['ln', '-s', os.path.join(HOME, 'smartopen', 'bin', 'smartopen'), os.path.join(HOME, 'bin', 'smartopen') ],
148 ['ln', '-s', os.path.join(HOME, 'silvermirror', 'bin', 'silvermirror'), os.path.join(HOME, 'bin', 'silvermirror') ],
149 ]
150 execute(*postinstall_commands)
151 else:
152 print "git not installed"
153
154
140 155
141 def main(args=sys.argv[1:]): 156 def main(args=sys.argv[1:]):
142 157
143 # go home 158 # go home
144 os.chdir(HOME) 159 os.chdir(HOME)
148 parser = optparse.OptionParser(usage=usage, description=__doc__) 163 parser = optparse.OptionParser(usage=usage, description=__doc__)
149 parser.add_option('--deb', '--dpkg', '--debian-packages', 164 parser.add_option('--deb', '--dpkg', '--debian-packages',
150 dest='debian_packages', 165 dest='debian_packages',
151 action='store_true', default=False, 166 action='store_true', default=False,
152 help="display debian packages to install") 167 help="display debian packages to install")
168 parser.add_option('-l', '--list', '--list-steps',
169 dest='list_steps',
170 action='store_true', default=False,
171 help="list steps to be run")
153 options, args = parser.parse_args() 172 options, args = parser.parse_args()
154 173
155 # plan steps 174 # plan steps
156 steps = [InitializeRepository] 175 steps = [InitializeRepository, UbuntuPackages]
176 if options.debian_packages:
177 steps = [DebianPackages]
178
179 if options.list_steps:
180 # list steps if specified
181 for step in steps:
182 print step
157 183
158 # execute steps 184 # execute steps
159 for step in steps: 185 for step in steps:
160 pass # TODO 186 instance = step()
187 instance()
161 188
162 if __name__ == '__main__': 189 if __name__ == '__main__':
163 main() 190 main()