]> scripts.mit.edu Git - wizard.git/blob - wizard/command/install.py
e736fc967a4763870ef548ba859f929b8a6fbffa
[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, baton)
12     # XXX: do something smart if -scripts is not at the end
13     app = args[0]
14     dir = args[1]
15     if os.path.exists(dir):
16         raise DirectoryExistsError
17     appname, _, version = app.partition('-')
18     application = deploy.applications()[appname]
19     sh = shell.Shell()
20     sh.call("git", "clone", "--shared", application.repository(options.srv_path), dir)
21     with util.ChangeDirectory(dir):
22         if version:
23             sh.call("git", "reset", "--hard", app)
24         # this command's stdin should be hooked up to ours
25         try:
26             configure_args = args[2:] + command.makeBaseArgs(options)
27             sh.call("wizard", "configure", *configure_args, interactive=True)
28         except shell.PythonCallError:
29             sys.exit(1)
30
31 def parse_args(argv, baton):
32     usage = """usage: %prog install [APP [DIR -- [SETUPARGS]]]
33
34 Autoinstalls the application APP in the directory
35 DIR.  SETUPARGS are arguments that are passed to
36 'wizard configure', see 'wizard configure APP --help'
37 for possible arguments.
38
39 WARNING: This command's API may change."""
40     parser = command.WizardOptionParser(usage)
41     baton.push(parser, "srv_path")
42     options, args = parser.parse_all(argv)
43     # XXX: in the future, not specifying stuff is supported, since
44     # we'll prompt for it interactively
45     if not args:
46         parser.error("must specify application and directory")
47     elif len(args) == 1:
48         parser.error("must specify directory")
49     return options, args
50
51 class DirectoryExistsError(wizard.Error):
52     def __str__(self):
53         return "Directory already exists"