]> scripts.mit.edu Git - wizard.git/blob - wizard/command/install.py
Remove directory/application interactivity.
[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, prompt, shell, util
7 from wizard.install import installopt, interactive
8
9 def main(argv, baton):
10     old_options, args = parse_args(argv, baton)
11
12     input = prompt.make(old_options.prompt, old_options.non_interactive)
13
14     appstr = args[0]
15     dir = args[1]
16
17     if os.path.exists(dir) and os.listdir(dir):
18         raise DirectoryExistsError
19
20     appname, _, version = appstr.partition('-')
21     application = app.applications()[appname]
22
23     # get configuration
24     schema = application.install_schema
25     options = None
26     opthandler = installopt.Controller(dir, schema)
27     ihandler = interactive.Controller(dir, schema, input)
28     parser = command.WizardOptionParser()
29     opthandler.push(parser)
30     options, _ = parser.parse_all(args[2:] + command.make_base_args(old_options)) # accumulate
31     if old_options.non_interactive:
32         opthandler.handle(options)
33     else:
34         ihandler.ask(options)
35
36     sh = shell.Shell()
37     input.infobox("Copying files (this may take a while)...")
38     sh.call("git", "clone", "-q", "--shared", application.repository(old_options.srv_path), dir)
39     with util.ChangeDirectory(dir):
40         if version:
41             # XXX: do something smart if -scripts is not at the end
42             sh.call("git", "reset", "-q", "--hard", appstr)
43         input.infobox("Installing...")
44         application.install(distutils.version.LooseVersion(version), options)
45         git.commit_configure()
46     input.infobox("Congratulations, your new install is now accessible at http://%s%s" % (options.web_host, options.web_path))
47
48 def parse_args(argv, baton):
49     usage = """usage: %prog install APP DIR [ -- SETUPARGS ]
50
51 Autoinstalls the application APP in the directory
52 DIR.  SETUPARGS are arguments that are passed to
53 'wizard configure', see 'wizard configure APP --help'
54 for possible arguments.  If arguments are missing
55 this command will interactively ask for them.
56 """
57     parser = command.WizardOptionParser(usage)
58     parser.add_option("--prompt", dest="prompt", action="store_true",
59             default=False, help="Force to use non-ncurses interactive interface")
60     parser.add_option("--non-interactive", dest="non_interactive", action="store_true",
61             default=False, help="Force program to be non-interactive")
62     baton.push(parser, "srv_path")
63     options, args = parser.parse_all(argv)
64     if len(args) < 2:
65         parser.error("not enough arguments")
66     return options, args
67
68 class DirectoryExistsError(wizard.Error):
69     def __str__(self):
70         return "Directory already exists and is not empty"