X-Git-Url: http://git.tremily.us/?p=hooke.git;a=blobdiff_plain;f=hooke%2Fplugin%2Fconfig.py;h=ea1b0397f9d657ab84008cfab5e5ef87062612d5;hp=466ca1f32f09c1555182cef0615c58a345a38034;hb=ec8f0b586953b23dea6ff24060610f56a7dbf975;hpb=b90995fb4b6d8151df862d40edc8c369d7052cfa diff --git a/hooke/plugin/config.py b/hooke/plugin/config.py index 466ca1f..ea1b039 100644 --- a/hooke/plugin/config.py +++ b/hooke/plugin/config.py @@ -32,7 +32,7 @@ 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 @@ -95,7 +95,7 @@ class SetCommand (Command): outqueue.put(ReloadUserInterfaceConfig(hooke.config)) class PrintCommand (Command): - """Get the current value of all configuration options. + """Get the current configuration file text. """ def __init__(self, plugin): super(PrintCommand, self).__init__( @@ -105,3 +105,29 @@ class PrintCommand (Command): 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(params['output'], 'w') + hooke.config.write(fp=f) + finally: + if f != None: + f.close()