]> scripts.mit.edu Git - wizard.git/blob - wizard/command/install.py
Implement less braindead help messages for installation.
[wizard.git] / wizard / command / install.py
1 import os
2 import shutil
3 import logging
4 import errno
5 import sys
6
7 import wizard
8 from wizard import command, deploy, shell, util
9
10 def main(argv, baton):
11     options, args = parse_args(argv)
12     # XXX: do something smart if -scripts is not at the end
13     dir = args[0]
14     if os.path.exists(dir):
15         raise DirectoryExistsError
16     appname, _, version = options.app.partition('-')
17     app = deploy.applications()[appname]
18     sh = shell.Shell()
19     sh.call("git", "clone", "--shared", app.repository, dir)
20     with util.ChangeDirectory(dir):
21         if version:
22             sh.call("git", "checkout", options.app)
23         # this command's stdin should be hooked up to ours
24         try:
25             sh.call("wizard", "configure", *args[1:], interactive=True)
26         except shell.PythonCallError:
27             sys.exit(1)
28
29 def parse_args(argv):
30     usage = """usage: %prog install [APP [DIR -- [SETUPARGS]]]
31
32 Autoinstalls the application APP in the directory
33 DIR.  SETUPARGS are arguments that are passed to
34 'wizard configure', see 'wizard configure APP --help'
35 for possible arguments.
36
37 WARNING: This command's API may change."""
38     parser = command.WizardOptionParser(usage)
39     parser.add_option("--app", dest="app",
40             help="Application to install, optionally specifying a version as APP-VERSION")
41     options, args = parser.parse_all(argv)
42     if not args:
43         # XXX: in the future, not specifying stuff is supported, since
44         # we'll prompt for it interactively
45         parser.error("must specify application")
46     return options, args
47
48 class DirectoryExistsError(wizard.Error):
49     def __str__(self):
50         return "Directory already exists"