]> scripts.mit.edu Git - wizard.git/blob - bin/wizard
aad6c9258a5050ecbf67f747c97331076a74ab7f
[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",
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",
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     try:
43         command_name = args[0]
44     except IndexError:
45         parser.print_help()
46         raise SystemExit(1)
47     baton.add("--log-dir", dest="log_dir",
48         default=getenvpath("WIZARD_LOG_DIR") or "/tmp/wizard-%s" % command_name,
49         help="Log files for Wizard children processes are placed here.")
50     if command_name == "help":
51         try:
52             help_module = get_command(rest_argv[0])
53         except ImportError:
54             parser.error("invalid action")
55         except IndexError:
56             parser.print_help()
57             raise SystemExit(1)
58         help_module.main(['--help'], baton)
59     # Dispatch commands
60     try:
61         command_module = get_command(command_name)
62     except ImportError:
63         parser.error("invalid action")
64     command_module.main(rest_argv, baton)
65
66 def get_command(name):
67     name = name.replace("-", "_")
68     __import__("wizard.command." + name)
69     return getattr(wizard.command, name)
70
71 def getenvpath(name):
72     val = os.getenv(name)
73     if val:
74         val = os.path.abspath(val)
75     return val
76
77 if __name__ == "__main__":
78     main()
79