6 from wizard import app, command, git, prompt, shell, util
7 from wizard.install import installopt, interactive
10 old_options, args = parse_args(argv, baton)
12 input = prompt.make(old_options.prompt, old_options.non_interactive)
15 dir = os.path.abspath(args[1])
17 if not old_options.help and os.path.exists(dir) and os.listdir(dir):
18 raise DirectoryExistsError
20 appname, _, version = appstr.partition('-')
21 application = app.applications()[appname]
24 schema = application.install_schema
27 opthandler = installopt.Controller(dir, schema)
28 ihandler = interactive.Controller(dir, schema, input)
29 parser = command.WizardOptionParser("""usage: %%prog install %s DIR [ -- SETUPARGS ]
31 Autoinstalls the application %s in the directory DIR.""" % (appname, appname))
32 configure_parser(parser, baton)
33 opthandler.push(parser)
37 options, _ = parser.parse_all(args[2:] + command.make_base_args(old_options))
38 if old_options.non_interactive:
39 opthandler.handle(options)
44 input.infobox("Copying files (this may take a while)...")
45 sh.call("git", "clone", "-q", "--shared", application.repository(old_options.srv_path), dir)
46 with util.ChangeDirectory(dir):
47 if version and version != "head-scripts": # for ease in testing
48 sh.call("git", "reset", "-q", "--hard", appstr)
49 input.infobox("Installing...")
50 application.install(distutils.version.LooseVersion(version), options)
51 if not old_options.no_commit:
52 git.commit_configure()
53 input.infobox("Congratulations, your new install is now accessible at:\n\nhttp://%s%s" % (options.web_host, options.web_path), width=80)
55 def configure_parser(parser, baton):
56 parser.add_option("--prompt", dest="prompt", action="store_true",
57 default=False, help="Force to use non-ncurses interactive interface")
58 parser.add_option("--non-interactive", dest="non_interactive", action="store_true",
59 default=False, help="Force program to be non-interactive and use SETUPARGS. Use --help with APP to find argument names.")
60 parser.add_option("--no-commit", dest="no_commit", action="store_true",
61 default=False, help="Do not generate an 'installation commit' after configuring the application.")
62 baton.push(parser, "srv_path")
64 def parse_args(argv, baton):
65 usage = """usage: %prog install APP DIR [ -- SETUPARGS ]
67 Autoinstalls the application APP in the directory DIR.
68 This command will interactively ask for information to
69 complete the autoinstall.
71 You can also use --help with APP and DIR to find out what
72 are required SETUPARGS if you want to run this non-interactively
73 (the distribution of required and optional arguments may change
74 depending on what directory you are installing to.)"""
75 parser = command.WizardOptionParser(usage, store_help=True)
76 configure_parser(parser, baton)
77 options, args = parser.parse_all(argv)
83 args.append(os.getcwd())
86 parser.error("not enough arguments")
89 class DirectoryExistsError(wizard.Error):
91 return "Directory already exists and is not empty"