import os import shutil import logging import errno import sys import wizard from wizard import command, deploy, shell, util def main(argv, baton): options, args = parse_args(argv) # XXX: do something smart if -scripts is not at the end dir = args[0] if os.path.exists(dir): raise DirectoryExistsError appname, _, version = options.app.partition('-') app = deploy.applications()[appname] sh = shell.Shell() sh.call("git", "clone", "--shared", app.repository, dir) with util.ChangeDirectory(dir): if version: sh.call("git", "checkout", options.app) # this command's stdin should be hooked up to ours try: sh.call("wizard", "configure", *args[1:], interactive=True) except shell.PythonCallError: sys.exit(1) def parse_args(argv): usage = """usage: %prog install [--app APP] [DIR -- [SETUPARGS]] Autoinstalls an application.""" parser = command.WizardOptionParser(usage) parser.add_option("--app", dest="app", help="Application to install, optionally specifying a version as APP-VERSION") options, args = parser.parse_all(argv) if not args: # XXX: in the future, not specifying stuff is supported, since # we'll prompt for it interactively parser.error("must specify application") return options, args class DirectoryExistsError(wizard.Error): def __str__(self): return "Directory already exists"