]> scripts.mit.edu Git - wizard.git/blob - bin/wizard
Move a number of common parameters to the baton.
[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     migrate         Migrate autoinstalls from old format to Git-based format
24     prepare-config  Prepares configuration files for versioning
25     research        Print statistics about a possible upgrade
26     summary         Generate statistics (see help for subcommands)
27     upgrade         Upgrades an autoinstall to the latest version
28
29 See '%prog help COMMAND' for more information on a specific command."""
30
31     parser = optparse.OptionParser(usage)
32     parser.disable_interspersed_args()
33     _, args = parser.parse_args() # no global options
34     rest_argv = args[1:]
35     baton = command.OptionBaton()
36     baton.add("--versions-path", dest="versions_path", metavar="PATH",
37         default=getenvpath("WIZARD_VERSIONS_PATH") or "/afs/athena.mit.edu/contrib/scripts/sec-tools/store/versions",
38         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.")
39     baton.add("--srv-path", dest="srv_path", metavar="PATH",
40         default=getenvpath("WIZARD_SRV_PATH") or "/afs/athena.mit.edu/contrib/scripts/git/autoinstalls",
41         help="Location of autoinstall Git repositories, such that $REPO_PATH/$APP.git is a repository (for development work).  Environment variable is WIZARD_SRV_PATH.")
42     baton.add("--dry-run", dest="dry_run", action="store_true",
43             default=False, help="Print the results of the operation without actually executing them")
44     # common variables for mass commands
45     baton.add("--seen", dest="seen",
46             default=None, help="File to read/write paths of already processed installs."
47             "These will be skipped.")
48     baton.add("--no-parallelize", dest="no_parallelize", action="store_true",
49             default=False, help="Turn off parallelization")
50     baton.add("--max-processes", dest="max_processes", type="int", metavar="N",
51             default=10, help="Maximum subprocesses to run concurrently")
52     baton.add("--limit", dest="limit", type="int",
53             default=None, help="Limit the number of autoinstalls to look at.")
54     try:
55         command_name = args[0]
56     except IndexError:
57         parser.print_help()
58         raise SystemExit(1)
59     baton.add("--log-dir", dest="log_dir",
60         default=getenvpath("WIZARD_LOG_DIR") or "/tmp/wizard-%s" % command_name,
61         help="Log files for Wizard children processes are placed here.")
62     if command_name == "help":
63         try:
64             help_module = get_command(rest_argv[0])
65         except ImportError:
66             parser.error("invalid action")
67         except IndexError:
68             parser.print_help()
69             raise SystemExit(1)
70         help_module.main(['--help'], baton)
71     # Dispatch commands
72     try:
73         command_module = get_command(command_name)
74     except ImportError:
75         parser.error("invalid action")
76     command_module.main(rest_argv, baton)
77
78 def get_command(name):
79     name = name.replace("-", "_")
80     __import__("wizard.command." + name)
81     return getattr(wizard.command, name)
82
83 def getenvpath(name):
84     val = os.getenv(name)
85     if val:
86         val = os.path.abspath(val)
87     return val
88
89 if __name__ == "__main__":
90     main()
91