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