]> scripts.mit.edu Git - wizard.git/blob - wizard/install/installopt.py
Use CLI installer for MediaWiki 1.17.0 and later.
[wizard.git] / wizard / install / installopt.py
1 import optparse
2
3 def attr_to_option(variable):
4     """
5     Converts Python attribute names to command line options.
6
7     >>> attr_to_option("foo_bar")
8     '--foo-bar'
9     """
10     return '--' + variable.replace('_', '-')
11
12 class Controller(object):
13     """
14     Simple controller that actually delegates to :class:`optparse.OptionParser`.
15     """
16     def __init__(self, dir, schema):
17         self.dir = dir
18         self.schema = schema
19     def push(self, parser):
20         """Pushes arg schema to :class:`optparse.OptionParser`."""
21         required = optparse.OptionGroup(parser, "Required Arguments (SETUPARGS)")
22         optional = optparse.OptionGroup(parser, "Optional Arguments (SETUPARGS)")
23         for arg in self.schema.args.values():
24             group = arg.name in self.schema.provides and optional or required
25             group.add_option(attr_to_option(arg.name), dest=arg.name, metavar=arg.type,
26                     default=None, help=arg.help)
27         parser.add_option_group(required)
28         parser.add_option_group(optional)
29     def handle(self, options):
30         """
31         Performs post-processing for the options, including throwing
32         errors if not all arguments are specified.
33         """
34         self.schema.load(options)