]> scripts.mit.edu Git - wizard.git/blobdiff - bin/wizard
Move a bunch of summary items to full class commands.
[wizard.git] / bin / wizard
index 916a292528aa7d21b6176063af0220b0f6e470ce..95ad1725ff9fcec3c7b3a4954d95c92e9a60f8a2 100755 (executable)
@@ -4,54 +4,58 @@ import os
 import optparse
 import sys
 
-# Add lib to path
-sys.path.insert(0,os.path.abspath(os.path.join(__file__,'../../lib')))
-import wizard.command
+sys.path.insert(0,os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
+
+import wizard
+from wizard import command
 
 def main():
-    usage = """usage: %prog [-d|--version-dir] COMMAND [ARGS]
+    usage = """usage: %prog COMMAND [ARGS]
 
 Wizard is a Git-based autoinstall management system for scripts.
 
 Its commands are:
-    info        Reports information about an autoinstall
-    migrate     Migrate autoinstalls from old format to Git-based format
-    summary     Generate statistics about autoinstalls
+    errors          Lists all broken autoinstall metadata
+    info            Reports information about an autoinstall
+    list            Lists autoinstalls, with optional filtering
+    massmigrate     Performs mass migration of autoinstalls of an application
+    migrate         Migrate autoinstalls from old format to Git-based format
+    summary         Generate statistics (see help for subcommands)
+    upgrade         Upgrades an autoinstall to the latest version
 
 See '%prog help COMMAND' for more information on a specific command."""
 
     parser = optparse.OptionParser(usage)
-    parser.add_option("-d", "--version-dir", dest="version_dir",
-            default="/afs/athena.mit.edu/contrib/scripts/sec-tools/store/versions",
-            help="Location of parallel-find output")
-    # Find the end of the "global" options
-    i = 1
+    parser.disable_interspersed_args()
+    _, args = parser.parse_args() # no global options
+    rest_argv = args[1:]
+    baton = command.OptionBaton()
+    baton.add("--versions-path", dest="versions_path",
+        default="/afs/athena.mit.edu/contrib/scripts/sec-tools/store/versions",
+        help="Location of parallel-find output directory, or a file containing a newline separated list of 'all autoinstalls' (for testing).")
     try:
-        while not sys.argv[i] or sys.argv[i][0] == '-':
-            if sys.argv[i] == "-h" or sys.argv[i] == "--help":
-                parser.print_help()
-                raise SystemExit(-1)
-            i += 1
+        command_name = args[0]
     except IndexError:
         parser.print_help()
-        raise SystemExit(-1)
-    options, args = parser.parse_args(sys.argv[1:i+1])
-    rest_argv = sys.argv[i+1:]
-    command = args[0] # shouldn't fail
-    if command == "help":
+        raise SystemExit(1)
+    if command_name == "help":
         try:
-            getattr(wizard.command, rest_argv[0])(['-h'], options)
-        except AttributeError:
+            get_command(rest_argv[0]).main(['--help'], baton)
+        except (AttributeError, ImportError):
             parser.error("invalid action")
         except IndexError:
             parser.print_help()
-            raise SystemExit(-1)
+            raise SystemExit(1)
     # Dispatch commands
     try:
-        command_module = getattr(wizard.command, command)
-    except AttributeError:
+        command_module = get_command(command_name)
+    except (AttributeError, ImportError):
         parser.error("invalid action")
-    command_module.main(rest_argv, options)
+    command_module.main(rest_argv, baton)
+
+def get_command(name):
+    __import__("wizard.command." + name)
+    return getattr(wizard.command, name)
 
 if __name__ == "__main__":
     main()