1 """The `config` module provides :class:`ConfigPlugin` and several
2 associated :class:`hooke.command.Command`\s for handling
3 :mod:`hooke.config` classes.
6 from StringIO import StringIO
8 from ..command import Command, Argument, Failure
9 from ..interaction import ReloadUserInterfaceConfig
10 from ..plugin import Builtin
13 class ConfigPlugin (Builtin):
15 super(ConfigPlugin, self).__init__(name='config')
18 return [GetCommand(), SetCommand(), PrintCommand()]
21 # Define common or complicated arguments
23 SectionArgument = Argument(
24 name='section', type='string', optional=False,
26 Configuration section to act on.
29 OptionArgument = Argument(
30 name='option', type='string', optional=False,
32 Configuration option to act on.
38 class GetCommand (Command):
39 """Get the current value of a configuration option.
42 super(GetCommand, self).__init__(
44 arguments=[SectionArgument, OptionArgument],
47 def _run(self, hooke, inqueue, outqueue, params):
48 outqueue.put(hooke.config.get(params['section'], params['option']))
50 class SetCommand (Command):
51 """Set the current value of a configuration option.
53 Currently many config options are read at startup time, and config
54 dicts are passed out to their target classes. This means that changes
55 to the central :attr:`hooke.hooke.Hooke.config` location *will not* be
56 noticed by the target classes unless the configuration is reloaded.
57 This reloading may cause problems in poorly written UIs.
60 super(SetCommand, self).__init__(
63 SectionArgument, OptionArgument,
65 name='value', type='string', optional=False,
66 help='Value to set.'),
70 def _run(self, hooke, inqueue, outqueue, params):
71 hooke.config.set(params['section'], params['option'], params['value'])
75 # notify UI to update config
76 outqueue.put(ReloadUserInterfaceConfig(hooke.config))
78 class PrintCommand (Command):
79 """Get the current value of a configuration option.
82 super(PrintCommand, self).__init__(
83 name='print config', help=self.__doc__)
85 def _run(self, hooke, inqueue, outqueue, params):
87 hooke.config.write(out)
88 outqueue.put(out.getvalue())