]> scripts.mit.edu Git - wizard.git/blob - bin/wizard
Various refinements from our mass-upgrade run.
[wizard.git] / bin / wizard
1 #!/usr/bin/env python
2
3 import os
4 import optparse
5 import sys
6
7 sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
8
9 import wizard
10 from wizard import command
11
12 def main():
13     usage = """usage: %prog COMMAND [ARGS]
14
15 Wizard is a Git-based autoinstall management system for scripts.
16
17 Its commands are:
18     configure       Configures an autoinstall (database, etc) to work
19     errors          Lists all broken autoinstall metadata
20     install         Installs an application
21     list            Lists autoinstalls, with optional filtering
22     mass-migrate    Performs mass migration of autoinstalls of an application
23     mass-upgrade    Performs mass upgrade of autoinstalls of an application
24     migrate         Migrate autoinstalls from old format to Git-based format
25     prepare-config  Prepares configuration files for versioning
26     research        Print statistics about a possible upgrade
27     summary         Generate statistics (see help for subcommands)
28     upgrade         Upgrades an autoinstall to the latest version
29
30 See '%prog help COMMAND' for more information on a specific command."""
31
32     parser = optparse.OptionParser(usage)
33     parser.disable_interspersed_args()
34     _, args = parser.parse_args() # no global options
35     rest_argv = args[1:]
36     baton = command.OptionBaton()
37     baton.add("--versions-path", dest="versions_path", metavar="PATH",
38         default=getenvpath("WIZARD_VERSIONS_PATH") or "/afs/athena.mit.edu/contrib/scripts/sec-tools/store/versions",
39         help="Location of parallel-find output directory, or a file containing a newline separated list of 'all autoinstalls' (for development work).  Environment variable is WIZARD_VERSIONS_PATH.")
40     baton.add("--srv-path", dest="srv_path", metavar="PATH",
41         default=getenvpath("WIZARD_SRV_PATH") or "/afs/athena.mit.edu/contrib/scripts/git/autoinstalls",
42         help="Location of autoinstall Git repositories, such that $REPO_PATH/$APP.git is a repository (for development work).  Environment variable is WIZARD_SRV_PATH.")
43     baton.add("--dry-run", dest="dry_run", action="store_true",
44             default=False, help="Performs the operation without actually modifying any files.  Use in combination with --verbose to see commands that will be run.")
45     # common variables for mass commands
46     baton.add("--seen", dest="seen",
47             default=None, help="File to read/write paths of already processed installs."
48             "These will be skipped.")
49     baton.add("--no-parallelize", dest="no_parallelize", action="store_true",
50             default=False, help="Turn off parallelization")
51     baton.add("--max-processes", dest="max_processes", type="int", metavar="N",
52             default=40, help="Maximum subprocesses to run concurrently")
53     baton.add("--limit", dest="limit", type="int",
54             default=None, help="Limit the number of autoinstalls to look at.")
55     try:
56         command_name = args[0]
57     except IndexError:
58         parser.print_help()
59         raise SystemExit(1)
60     baton.add("--log-dir", dest="log_dir",
61         default=getenvpath("WIZARD_LOG_DIR") or "/tmp/wizard-%s" % command_name,
62         help="Log files for Wizard children processes are placed here.")
63     if command_name == "help":
64         try:
65             help_module = get_command(rest_argv[0])
66         except ImportError:
67             parser.error("invalid action")
68         except IndexError:
69             parser.print_help()
70             raise SystemExit(1)
71         help_module.main(['--help'], baton)
72     # Dispatch commands
73     try:
74         command_module = get_command(command_name)
75     except ImportError:
76         parser.error("invalid action")
77     command_module.main(rest_argv, baton)
78
79 def get_command(name):
80     name = name.replace("-", "_")
81     __import__("wizard.command." + name)
82     return getattr(wizard.command, name)
83
84 def getenvpath(name):
85     val = os.getenv(name)
86     if val:
87         val = os.path.abspath(val)
88     return val
89
90 if __name__ == "__main__":
91     main()
92