]> scripts.mit.edu Git - wizard.git/blob - bin/wizard
Add more clarifications to TODO.
[wizard.git] / bin / wizard
1 #!/usr/bin/env python
2
3 import os
4 import optparse
5 import sys
6
7 # Add lib to path
8 sys.path.insert(0,os.path.abspath(os.path.join(__file__,'../../lib')))
9 import wizard.command
10
11 def main():
12     usage = """usage: %prog [-d|--version-dir] COMMAND [ARGS]
13
14 Wizard is a Git-based autoinstall management system for scripts.
15
16 Its commands are:
17     info            Reports information about an autoinstall
18     massmigrate     Performs mass migration of autoinstalls of an application
19     migrate         Migrate autoinstalls from old format to Git-based format
20     summary         Generate statistics about autoinstalls
21
22 See '%prog help COMMAND' for more information on a specific command."""
23
24     parser = optparse.OptionParser(usage)
25     parser.add_option("-d", "--version-dir", dest="version_dir",
26             default="/afs/athena.mit.edu/contrib/scripts/sec-tools/store/versions",
27             help="Location of parallel-find output")
28     # Find the end of the "global" options
29     i = 1
30     try:
31         while not sys.argv[i] or sys.argv[i][0] == '-':
32             if sys.argv[i] == "-h" or sys.argv[i] == "--help":
33                 parser.print_help()
34                 raise SystemExit(-1)
35             i += 1
36     except IndexError:
37         parser.print_help()
38         raise SystemExit(-1)
39     options, args = parser.parse_args(sys.argv[1:i+1])
40     rest_argv = sys.argv[i+1:]
41     command = args[0] # shouldn't fail
42     if command == "help":
43         try:
44             getattr(wizard.command, rest_argv[0])(['-h'], options)
45         except AttributeError:
46             parser.error("invalid action")
47         except IndexError:
48             parser.print_help()
49             raise SystemExit(-1)
50     # Dispatch commands
51     try:
52         command_fn = getattr(wizard.command, command)
53     except AttributeError:
54         parser.error("invalid action")
55     command_fn(rest_argv, options)
56
57 if __name__ == "__main__":
58     main()
59