]> scripts.mit.edu Git - wizard.git/blob - wizard/install/installopt.py
Implement interactive mode without validation.
[wizard.git] / wizard / install / installopt.py
1 def attr_to_option(variable):
2     """
3     Converts Python attribute names to command line options.
4
5     >>> attr_to_option("foo_bar")
6     '--foo-bar'
7     """
8     return '--' + variable.replace('_', '-')
9
10 class Controller(object):
11     """
12     Simple controller that actually delegates to :class:`optparse.OptionParser`.
13     """
14     def __init__(self, dir, schema):
15         self.dir = dir
16         self.schema = schema
17     def push(self, parser):
18         """Pushes arg schema to :class:`optparse.OptionParser`."""
19         for arg in self.schema.args.values():
20             parser.add_option(attr_to_option(arg.name), dest=arg.name, metavar=arg.type,
21                     default=None, help=arg.help)
22     def handle(self, options):
23         """
24         Performs post-processing for the options, including throwing
25         errors if not all arguments are specified.
26         """
27         self.schema.commit(self.dir)
28         self.schema.load(options)