]> scripts.mit.edu Git - wizard.git/blob - wizard/command/configure.py
Refactoring.
[wizard.git] / wizard / command / configure.py
1 import logging
2 import optparse
3 import sys
4
5 from wizard import command, deploy, git
6
7 def main(argv, baton):
8
9     usage = """usage: %prog configure [ARGS]
10
11 Takes an already cloned working copy and configures the
12 application, running any installer scripts and creating
13 configuration files.  Options change depending on what
14 application is being configured in the current working directory.
15
16 This is a plumbing command, normal users should use
17 `%prog install`."""
18
19     # XXX: squick squick squick
20     if argv and argv[0][0] != '-':
21         if '--help' not in argv and '-h' not in argv:
22             argv.append('--help')
23     if '--help' in argv or '-h' in argv:
24         # Do a "fake parse" in order to get out the application name
25         parser = optparse.OptionParser(usage, add_help_option=False)
26         parser.add_option("--help", "-h", action="store_true")
27         options, args = parser.parse_args(argv)
28         try:
29             application = args[0]
30         except IndexError:
31             parser.error("Use 'wizard configure --help APP' to see APP-specific options.")
32     else:
33         tag = git.describe()
34         application, _, version = tag.partition('-')
35
36     app = deploy.applications()[application]
37     handler = app.install_handler
38
39     parser = command.WizardOptionParser(usage)
40     handler.push(parser)
41     options, args = parser.parse_all(argv)
42     handler.handle(options)
43
44     app.install(options)
45