import os import sys import distutils import wizard from wizard import app, command, git, shell, util from wizard.install import installopt def main(argv, baton): old_options, args = parse_args(argv, baton) # XXX: do something smart if -scripts is not at the end appstr = args[0] dir = args[1] if os.path.exists(dir): raise DirectoryExistsError appname, _, version = appstr.partition('-') application = app.applications()[appname] # get configuration schema = application.install_schema handler = installopt.Controller(schema) parser = command.WizardOptionParser() handler.push(parser) options, _ = parser.parse_all(args[2:] + command.make_base_args(old_options)) # accumulate handler.handle(options) sh = shell.Shell() sys.stderr.write("Copying files...\n") sh.call("git", "clone", "-q", "--shared", application.repository(old_options.srv_path), dir) with util.ChangeDirectory(dir): if version: sh.call("git", "reset", "-q", "--hard", appstr) sys.stderr.write("Installing...\n") application.install(distutils.version.LooseVersion(version), options) git.commit_configure() 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"