comparison python/install_config.py @ 591:542d329835ec

STUB: python/install_config.py
author Jeff Hammel <k0scist@gmail.com>
date Fri, 24 Jan 2014 18:40:45 -0800
parents e93b81d8a586
children 33b313fa1eb0
comparison
equal deleted inserted replaced
590:e93b81d8a586 591:542d329835ec
9 # TODO: 9 # TODO:
10 # - dl and get ~/web/sync.ini : 10 # - dl and get ~/web/sync.ini :
11 # ln -s /home/jhammel/web/sync.ini /home/jhammel/.silvermirror 11 # ln -s /home/jhammel/web/sync.ini /home/jhammel/.silvermirror
12 # - handle cases where config is autogenerated BUT you still want 12 # - handle cases where config is autogenerated BUT you still want
13 # to have some base (e.g. .gkrellm2/user_config) 13 # to have some base (e.g. .gkrellm2/user_config)
14 # - scp k0s.org:~/web/sync.ini ~/.silvermirror
15 # - make idempotent
14 16
15 # imports 17 # imports
16 import imp 18 import imp
17 import optparse 19 import optparse
18 import os 20 import os
21 23
22 # globals 24 # globals
23 SRC = 'http://k0s.org/hg/config' # config repository 25 SRC = 'http://k0s.org/hg/config' # config repository
24 HOME = os.environ['HOME'] # home directory 26 HOME = os.environ['HOME'] # home directory
25 27
28
26 ### standalone functions 29 ### standalone functions
30
31 def class_mapping(_type):
32 """returns a dict of (name, class) for objects in the current globals() of _type"""
33 return {name:cls for name, cls in globals().items() if cls.issubclass(_type)}
34
27 35
28 def execute(*commands, **kwargs): 36 def execute(*commands, **kwargs):
29 """execute a series of commands""" 37 """execute a series of commands"""
30 for command in commands: 38 for command in commands:
31 print (subprocess.list2cmdline(' '.join(command)) 39 print (subprocess.list2cmdline(' '.join(command)))
32 code = subprocess.call(command, **kwargs) 40 code = subprocess.call(command, **kwargs)
41 if code:
42 raise subprocess.CalledProcessError(code, command)
33 43
34 def install_develop(package): 44 def install_develop(package):
35 """install k0s.ware for development""" 45 """install k0s.ware for development"""
36 46
37 src = 'http://k0s.org/hg/%s' % package 47 src = 'http://k0s.org/hg/%s' % package
44 os.chdir(directory) 54 os.chdir(directory)
45 command = ['../../bin/python', 'setup.py', 'develop'] 55 command = ['../../bin/python', 'setup.py', 'develop']
46 execute(command) 56 execute(command)
47 os.chdir(old_directory) 57 os.chdir(old_directory)
48 58
59
49 ### generic step framework 60 ### generic step framework
50
51
52 61
53 class Step(object): 62 class Step(object):
54 @classmethod 63 @classmethod
55 def check(cls): 64 def check(cls):
56 """checks if the step may be run""" 65 """checks if the step may be run"""
169 help="display debian packages to install") 178 help="display debian packages to install")
170 parser.add_option('-l', '--list', '--list-steps', 179 parser.add_option('-l', '--list', '--list-steps',
171 dest='list_steps', 180 dest='list_steps',
172 action='store_true', default=False, 181 action='store_true', default=False,
173 help="list steps to be run and exit") 182 help="list steps to be run and exit")
183 parser.add_option('--all', dest='all',
184 action='store_true', default=False,
185 help="list all actions")
186 parser.add_option('--run', dest='run',
187 action='append',
188 help="run particular actions, in order")
174 options, args = parser.parse_args() 189 options, args = parser.parse_args()
175 190
176 # plan steps 191 # plan steps
177 steps = [InitializeRepository, DebianPackages] 192 steps = [InitializeRepository, DebianPackages]
178 if options.debian_packages: 193 if options.debian_packages:
182 # list steps if specified 197 # list steps if specified
183 for step in steps: 198 for step in steps:
184 print(step.name()) 199 print(step.name())
185 parser.exit() 200 parser.exit()
186 201
202 if options.all:
203 # list available steps
204 for sorted([]):
205 raise NotImplementedError("TODO")
206
187 # execute steps 207 # execute steps
188 for step in steps: 208 for step in steps:
189 instance = step() 209 instance = step()
190 instance() 210 instance()
191 211