#!/usr/bin/env python
"""
-This script generates basic statistics about our autoinstalls.
+This script does everything autoinstalls!
+
+Specifically, it:
+* Generates basic statistics about autoinstall versions
+* Migrates autoinstalls to the new Git format
"""
import os
"""Hash table for looking up string application name to instance"""
applications = dict([(n,Application(n)) for n in application_list ])
+def getInstallLines(global_options):
+ vd = global_options.version_dir
+ try:
+ return fileinput.input([vd + "/" + f for f in os.listdir(vd)])
+ except OSError:
+ print "No permissions; check if AFS is mounted"
+ raise SystemExit(-1)
+
def main():
- usage = """usage: %prog [options] [application]
+ usage = """usage: %prog [-d|--version-dir] COMMAND [ARGS]
+
+Wizard is a Git-based autoinstall management system for scripts.
+
+Its commands are:
+ stat Generate statistics about autoinstalls
+
+See '%prog help COMMAND' for more information on a specific command.
+"""
+# migrate Migrate autoinstalls from old format to Git-based format
+
+ 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
+ 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
+ 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
+ commands = {
+ "stat": stat
+ }
+ if command == "help":
+ try:
+ commands[rest_argv[0]](['-h'], options)
+ except KeyError:
+ parser.error("invalid action")
+ except IndexError:
+ parser.print_usage()
+ raise SystemExit(-1)
+ # Dispatch commands
+ if command not in commands:
+ parser.error("invalid action")
+ return commands[command](rest_argv, options)
+
+def stat(argv, global_options):
+ usage = """usage: %prog stat [ARGS] APPS
Scans all of the collected data from parallel-find.pl, and
determines version histograms for our applications. You may
optionally pass application parameters to filter the installs.
Examples:
- %prog
+ %prog stat
Basic usage
- %prog mediawiki
+ %prog stat mediawiki
Displays only MediaWiki statistics
- %prog -v -q mediawiki-1.2.3
+ %prog stat -v -q mediawiki-1.2.3
Displays all deployments of this version"""
parser = optparse.OptionParser(usage)
parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
default=False, help="Print interesting directories")
parser.add_option("-q", "--quiet", dest="quiet", action="store_true",
default=False, help="Suppresses progress output")
- 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")
parser.add_option("--count-exists", dest="count_exists",
default=False, help="Count deployments that contain a file")
- # There should be machine friendly output
- options, show = parser.parse_args()
+ options, show = parser.parse_args(argv)
+ fi = getInstallLines(global_options)
if not show: show = applications.keys()
show = frozenset(show)
- vd = options.version_dir
- try:
- fi = fileinput.input([vd + "/" + f for f in os.listdir(vd)])
- except OSError:
- print "No permissions; check if AFS is mounted"
- raise SystemExit(-1)
errors = 0
unrecognized = 0
processed = 0
printer = Printer(options.quiet, options.verbose)
- # I really don't like this boolean
- hanging = False # whether or not we last outputted a newline
printer.tweet("Processing")
for line in fi:
printer.tick()