]> scripts.mit.edu Git - wizard.git/blob - wizard/command/install.py
Change wizard install to not make external code.
[wizard.git] / wizard / command / install.py
1 import os
2 import sys
3 import distutils
4
5 import wizard
6 from wizard import app, command, git, shell, util
7 from wizard.install import installopt
8
9 def main(argv, baton):
10     old_options, args = parse_args(argv, baton)
11     # XXX: do something smart if -scripts is not at the end
12     appstr = args[0]
13     dir = args[1]
14     if os.path.exists(dir):
15         raise DirectoryExistsError
16     appname, _, version = appstr.partition('-')
17     application = app.applications()[appname]
18
19     # get configuration
20     schema = application.install_schema
21     handler = installopt.Controller(schema)
22     parser = command.WizardOptionParser()
23     handler.push(parser)
24     options, _ = parser.parse_all(args[2:] + command.make_base_args(old_options)) # accumulate
25     handler.handle(options)
26
27     sh = shell.Shell()
28     sys.stderr.write("Copying files...\n")
29     sh.call("git", "clone", "-q", "--shared", application.repository(old_options.srv_path), dir)
30     with util.ChangeDirectory(dir):
31         if version:
32             sh.call("git", "reset", "-q", "--hard", appstr)
33         sys.stderr.write("Installing...\n")
34         application.install(distutils.version.LooseVersion(version), options)
35         git.commit_configure()
36
37 def parse_args(argv, baton):
38     usage = """usage: %prog install [APP [DIR -- [SETUPARGS]]]
39
40 Autoinstalls the application APP in the directory
41 DIR.  SETUPARGS are arguments that are passed to
42 'wizard configure', see 'wizard configure APP --help'
43 for possible arguments.
44
45 WARNING: This command's API may change."""
46     parser = command.WizardOptionParser(usage)
47     baton.push(parser, "srv_path")
48     options, args = parser.parse_all(argv)
49     # XXX: in the future, not specifying stuff is supported, since
50     # we'll prompt for it interactively
51     if not args:
52         parser.error("must specify application and directory")
53     elif len(args) == 1:
54         parser.error("must specify directory")
55     return options, args
56
57 class DirectoryExistsError(wizard.Error):
58     def __str__(self):
59         return "Directory already exists"