#!/usr/bin/env python
-"""
-This script does everything autoinstalls!
-
-Specifically, it:
-* Generates basic statistics about autoinstall versions
-* Migrates autoinstalls to the new Git format
-"""
-
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:
- stat Generate statistics about autoinstalls
+ configure Configures an autoinstall (database, etc) to work
+ errors Lists all broken autoinstall metadata
+ install Installs an application
+ list Lists autoinstalls, with optional filtering
+ mass-migrate Performs mass migration of autoinstalls of an application
+ migrate Migrate autoinstalls from old format to Git-based format
+ prepare-config Prepares configuration files for versioning
+ research Print statistics about a possible upgrade
+ 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.
-"""
-# migrate Migrate autoinstalls from old format to Git-based format
+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", metavar="PATH",
+ default=getenvpath("WIZARD_VERSIONS_PATH") or "/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 development work). Environment variable is WIZARD_VERSIONS_PATH.")
+ baton.add("--srv-path", dest="srv_path", metavar="PATH",
+ default=getenvpath("WIZARD_SRV_PATH") or "/afs/athena.mit.edu/contrib/scripts/git/autoinstalls",
+ help="Location of autoinstall Git repositories, such that $REPO_PATH/$APP.git is a repository (for development work). Environment variable is WIZARD_SRV_PATH.")
+ baton.add("--dry-run", dest="dry_run", action="store_true",
+ default=False, help="Print the results of the operation without actually executing them")
+ # common variables for mass commands
+ baton.add("--seen", dest="seen",
+ default=None, help="File to read/write paths of already processed installs."
+ "These will be skipped.")
+ baton.add("--no-parallelize", dest="no_parallelize", action="store_true",
+ default=False, help="Turn off parallelization")
+ baton.add("--max-processes", dest="max_processes", type="int", metavar="N",
+ default=10, help="Maximum subprocesses to run concurrently")
+ baton.add("--limit", dest="limit", type="int",
+ default=None, help="Limit the number of autoinstalls to look at.")
try:
- while not sys.argv[i] or sys.argv[i][0] == '-':
- if sys.argv[i] == "-h" or sys.argv[i] == "--help":
- parser.print_usage()
- raise SystemExit(-1)
- i += 1
+ command_name = args[0]
except IndexError:
- parser.error("no action specified")
- 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":
+ parser.print_help()
+ raise SystemExit(1)
+ baton.add("--log-dir", dest="log_dir",
+ default=getenvpath("WIZARD_LOG_DIR") or "/tmp/wizard-%s" % command_name,
+ help="Log files for Wizard children processes are placed here.")
+ if command_name == "help":
try:
- getattr(wizard.command, rest_argv[0])(['-h'], options)
- except AttributeError:
+ help_module = get_command(rest_argv[0])
+ except ImportError:
parser.error("invalid action")
except IndexError:
- parser.print_usage()
- raise SystemExit(-1)
+ parser.print_help()
+ raise SystemExit(1)
+ help_module.main(['--help'], baton)
# Dispatch commands
try:
- getattr(wizard.command, command).main(rest_argv, options)
- except AttributeError:
+ command_module = get_command(command_name)
+ except ImportError:
parser.error("invalid action")
+ command_module.main(rest_argv, baton)
+
+def get_command(name):
+ name = name.replace("-", "_")
+ __import__("wizard.command." + name)
+ return getattr(wizard.command, name)
+
+def getenvpath(name):
+ val = os.getenv(name)
+ if val:
+ val = os.path.abspath(val)
+ return val
if __name__ == "__main__":
main()