]> scripts.mit.edu Git - wizard.git/blob - bin/wizard
Change reporting and logging semantics.
[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 User commands:
18     backup          Backup data not on filesystem (database, etc)
19     install         Installs an application
20     migrate         Migrate autoinstalls from old format to Git-based format
21     restore         Restores files and database to previous version
22     upgrade         Upgrades an autoinstall to the latest version
23
24 Administrative commands:
25     blacklist       Marks an autoinstall to not try upgrades
26     errors          Lists all broken autoinstall metadata
27     list            Lists autoinstalls, with optional filtering
28     mass-migrate    Performs mass migration of autoinstalls of an application
29     mass-upgrade    Performs mass upgrade of autoinstalls of an application
30     research        Print statistics about a possible upgrade
31     summary         Generate statistics (see help for subcommands)
32
33 Utility commands:
34     configure       Configures an autoinstall (database, etc) to work
35     prepare-config  Prepares configuration files for versioning
36
37 See '%prog help COMMAND' for more information on a specific command."""
38
39     parser = optparse.OptionParser(usage)
40     parser.disable_interspersed_args()
41     _, args = parser.parse_args() # no global options
42     rest_argv = args[1:]
43     baton = command.OptionBaton()
44     baton.add("--versions-path", dest="versions_path", metavar="PATH",
45         default=getenvpath("WIZARD_VERSIONS_PATH") or "/afs/athena.mit.edu/contrib/scripts/sec-tools/store/versions",
46         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.")
47     baton.add("--srv-path", dest="srv_path", metavar="PATH",
48         default=getenvpath("WIZARD_SRV_PATH") or "/afs/athena.mit.edu/contrib/scripts/git/autoinstalls",
49         help="Location of autoinstall Git repositories, such that $REPO_PATH/$APP.git is a repository (for development work).  Environment variable is WIZARD_SRV_PATH.")
50     baton.add("--dry-run", dest="dry_run", action="store_true",
51             default=False, help="Performs the operation without actually modifying any files.  Use in combination with --verbose to see commands that will be run.")
52     # common variables for mass commands
53     baton.add("--seen", dest="seen",
54             default=None, help="File to read/write paths of successfully modified installs;"
55             "these will be skipped on re-runs.  If --log-dir is specified, this is automatically enabled.")
56     baton.add("--no-parallelize", dest="no_parallelize", action="store_true",
57             default=False, help="Turn off parallelization")
58     baton.add("--max-processes", dest="max_processes", type="int", metavar="N",
59             default=10, help="Maximum subprocesses to run concurrently")
60     baton.add("--limit", dest="limit", type="int",
61             default=None, help="Limit the number of autoinstalls to look at.")
62     baton.add("--user", "-u", dest="user",
63             default=None, help="Only mass migrate a certain user's installs.  No effect if versions_path is a file.")
64     try:
65         command_name = args[0]
66     except IndexError:
67         parser.print_help()
68         raise SystemExit(1)
69     baton.add("--log-dir", dest="log_dir",
70         default=getenvpath("WIZARD_LOG_DIR") or "/tmp/wizard-%s" % command_name,
71         help="Log files for Wizard children processes are placed here.")
72     if command_name == "help":
73         try:
74             help_module = get_command(rest_argv[0])
75         except ImportError:
76             parser.error("invalid action")
77         except IndexError:
78             parser.print_help()
79             raise SystemExit(1)
80         help_module.main(['--help'], baton)
81     # Dispatch commands
82     try:
83         command_module = get_command(command_name)
84     except ImportError:
85         parser.error("invalid action")
86     command_module.main(rest_argv, baton)
87
88 def get_command(name):
89     name = name.replace("-", "_")
90     __import__("wizard.command." + name)
91     return getattr(wizard.command, name)
92
93 def getenvpath(name):
94     val = os.getenv(name)
95     if val:
96         val = os.path.abspath(val)
97     return val
98
99 if __name__ == "__main__":
100     main()
101