-# Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
+# Copyright (C) 2010-2012 W. Trevor King <wking@drexel.edu>
#
# This file is part of Hooke.
#
:mod:`hooke.config` classes.
"""
+import os.path
from StringIO import StringIO
from ..command import Command, Argument, Failure
from ..interaction import ReloadUserInterfaceConfig
-from ..plugin import Builtin
+from . import Builtin
class ConfigPlugin (Builtin):
def __init__(self):
super(ConfigPlugin, self).__init__(name='config')
self._commands = [GetCommand(self), SetCommand(self),
- PrintCommand(self)]
+ PrintCommand(self), SaveCommand(self),]
# Define common or complicated arguments
hooke.config.set(params['section'], params['option'], params['value'])
# push config changes
hooke.load_log()
- hooke.load_plugins()
- hooke.load_drivers()
- hooke.load_ui() # for post-HookeRunner Hooke return.
+ hooke.configure_plugins()
+ hooke.configure_drivers()
+ hooke.configure_ui() # for post-HookeRunner Hooke return.
# notify UI to update config
outqueue.put(ReloadUserInterfaceConfig(hooke.config))
class PrintCommand (Command):
- """Get the current value of a configuration option.
+ """Get the current configuration file text.
"""
def __init__(self, plugin):
super(PrintCommand, self).__init__(
out = StringIO()
hooke.config.write(out)
outqueue.put(out.getvalue())
+
+
+class SaveCommand (Command):
+ """Save the current configuration options.
+ """
+ def __init__(self, plugin):
+ super(SaveCommand, self).__init__(
+ name='save config',
+ arguments=[
+ Argument(name='output', type='file',
+ help="""
+File name for the output configuration. Defaults to overwriting the
+most local loaded config file.
+""".strip()),
+ ],
+ help=self.__doc__, plugin=plugin)
+
+ def _run(self, hooke, inqueue, outqueue, params):
+ f = None
+ try:
+ if params['output'] != None:
+ f = open(os.path.expanduser(params['output']), 'w')
+ hooke.config.write(fp=f)
+ finally:
+ if f != None:
+ f.close()