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, baton) # XXX: do something smart if -scripts is not at the end app = args[0] dir = args[1] if os.path.exists(dir): raise DirectoryExistsError appname, _, version = app.partition('-') application = deploy.applications()[appname] sh = shell.Shell() sh.call("git", "clone", "-q", "--shared", application.repository(options.srv_path), dir) with util.ChangeDirectory(dir): if version: sh.call("git", "reset", "-q", "--hard", app) # this command's stdin should be hooked up to ours try: configure_args = args[2:] + command.make_base_args(options) sh.call("wizard", "configure", *configure_args, interactive=True) except shell.PythonCallError: sys.exit(1) def parse_args(argv, baton): usage = """usage: %prog install [APP [DIR -- [SETUPARGS]]] Autoinstalls the application APP in the directory DIR. SETUPARGS are arguments that are passed to 'wizard configure', see 'wizard configure APP --help' for possible arguments. WARNING: This command's API may change.""" parser = command.WizardOptionParser(usage) baton.push(parser, "srv_path") options, args = parser.parse_all(argv) # XXX: in the future, not specifying stuff is supported, since # we'll prompt for it interactively if not args: parser.error("must specify application and directory") elif len(args) == 1: parser.error("must specify directory") return options, args class DirectoryExistsError(wizard.Error): def __str__(self): return "Directory already exists"