]> scripts.mit.edu Git - wizard.git/blob - bin/wizard
Drastically improved TODO docs and bin.
[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     migrate     Migrate autoinstalls from old format to Git-based format
19     summary     Generate statistics about autoinstalls
20
21 See '%prog help COMMAND' for more information on a specific command."""
22
23     parser = optparse.OptionParser(usage)
24     parser.add_option("-d", "--version-dir", dest="version_dir",
25             default="/afs/athena.mit.edu/contrib/scripts/sec-tools/store/versions",
26             help="Location of parallel-find output")
27     # Find the end of the "global" options
28     i = 1
29     try:
30         while not sys.argv[i] or sys.argv[i][0] == '-':
31             if sys.argv[i] == "-h" or sys.argv[i] == "--help":
32                 parser.print_help()
33                 raise SystemExit(-1)
34             i += 1
35     except IndexError:
36         parser.print_help()
37         raise SystemExit(-1)
38     options, args = parser.parse_args(sys.argv[1:i+1])
39     rest_argv = sys.argv[i+1:]
40     command = args[0] # shouldn't fail
41     if command == "help":
42         try:
43             getattr(wizard.command, rest_argv[0])(['-h'], options)
44         except AttributeError:
45             parser.error("invalid action")
46         except IndexError:
47             parser.print_help()
48             raise SystemExit(-1)
49     # Dispatch commands
50     try:
51         command_module = getattr(wizard.command, command)
52     except AttributeError:
53         parser.error("invalid action")
54     command_module.main(rest_argv, options)
55
56 if __name__ == "__main__":
57     main()
58