import optparse import wizard.deploy as wd import sys class Printer(object): def __init__(self, quiet, verbose): self.i = 0 self.quiet = quiet self.verbose = verbose self.hanging = False def tick(self): self.i += 1 if not self.quiet and self.i % 10 == 0: sys.stdout.write(".") sys.stdout.flush() self.hanging = True def _hang(self): if self.hanging: self.hanging = False print def write(self, str = ""): self._hang() print str def qwrite(self, str = ""): if not self.quiet: self._hang print str def tweet(self, str = ""): if not self.quiet: self._hang() print str, # note comma def chat(self, str = ""): if self.verbose: self._hang() print str def summary(argv, global_options): usage = """usage: %prog summary [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 summary Basic usage %prog summary mediawiki Displays only MediaWiki statistics %prog summary -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("--count-exists", dest="count_exists", default=False, help="Count deployments that contain a file") options, show = parser.parse_args(argv) fi = wd.getInstallLines(global_options) if not show: show = wd.applications.keys() show = frozenset(show) errors = 0 unrecognized = 0 processed = 0 printer = Printer(options.quiet, options.verbose) printer.tweet("Processing") for line in fi: printer.tick() try: deploy = wd.Deployment.parse(line) except wd.DeploymentParseError: errors += 1 continue except wd.NoSuchApplication: unrecognized += 1 continue name = deploy.getApplication().name if name + "-" + str(deploy.getVersion()) in show: printer.write("%s-%s deployment at %s" \ % (name, deploy.getVersion(), deploy.location)) elif name in show: pass else: continue deploy.count() if options.count_exists: r = deploy.count_exists(options.count_exists) if r: printer.chat("Found " + options.count_exists + " in " + deploy.location) printer.write() for app in wd.applications.values(): if app.name not in show: continue printer.write(app.report()) printer.write() printer.write("With %d errors and %d unrecognized applications" % (errors, unrecognized))