# HG changeset patch # User Jeff Hammel # Date 1390617645 28800 # Node ID 542d329835ec4e6a123e198a65579c93fb9c0c41 # Parent e93b81d8a586857b341615c6490183c313fc12c0 STUB: python/install_config.py diff -r e93b81d8a586 -r 542d329835ec python/install_config.py --- a/python/install_config.py Fri Jan 24 17:53:23 2014 -0800 +++ b/python/install_config.py Fri Jan 24 18:40:45 2014 -0800 @@ -11,6 +11,8 @@ # ln -s /home/jhammel/web/sync.ini /home/jhammel/.silvermirror # - handle cases where config is autogenerated BUT you still want # to have some base (e.g. .gkrellm2/user_config) +# - scp k0s.org:~/web/sync.ini ~/.silvermirror +# - make idempotent # imports import imp @@ -23,13 +25,21 @@ SRC = 'http://k0s.org/hg/config' # config repository HOME = os.environ['HOME'] # home directory + ### standalone functions +def class_mapping(_type): + """returns a dict of (name, class) for objects in the current globals() of _type""" + return {name:cls for name, cls in globals().items() if cls.issubclass(_type)} + + def execute(*commands, **kwargs): """execute a series of commands""" for command in commands: - print (subprocess.list2cmdline(' '.join(command)) + print (subprocess.list2cmdline(' '.join(command))) code = subprocess.call(command, **kwargs) + if code: + raise subprocess.CalledProcessError(code, command) def install_develop(package): """install k0s.ware for development""" @@ -46,10 +56,9 @@ execute(command) os.chdir(old_directory) + ### generic step framework - - class Step(object): @classmethod def check(cls): @@ -171,6 +180,12 @@ dest='list_steps', action='store_true', default=False, help="list steps to be run and exit") + parser.add_option('--all', dest='all', + action='store_true', default=False, + help="list all actions") + parser.add_option('--run', dest='run', + action='append', + help="run particular actions, in order") options, args = parser.parse_args() # plan steps @@ -184,6 +199,11 @@ print(step.name()) parser.exit() + if options.all: + # list available steps + for sorted([]): + raise NotImplementedError("TODO") + # execute steps for step in steps: instance = step()