]> scripts.mit.edu Git - wizard.git/blob - wizard/command/summary/version.py
Move a bunch of summary items to full class commands.
[wizard.git] / wizard / command / summary / version.py
1 import math
2
3 from wizard import command, deploy, util
4
5 def main(argv, baton):
6     options, show = parse_args(argv, baton)
7     HISTOGRAM_WIDTH = 30
8     show = set()
9     c_version = util.Counter()
10     c_application = util.Counter()
11     for d in deploy.parse_install_lines(show, options):
12         version = d.app_version
13         c_version.count(version)
14         c_application.count(version.application)
15         show.add(version.application)
16     if not show:
17         print "No applications found"
18     for application in show:
19         print "%-16s %3d installs" % (application.name, c_application[application])
20         vmax = max(c_version[x] for x in application.versions.values())
21         for version in sorted(application.versions.values()):
22             v = c_version[version]
23             graph = '+' * int(math.ceil(float(v)/vmax * HISTOGRAM_WIDTH))
24             print "    %-12s %3d  %s" % (version.version, v, graph)
25         print
26
27 def parse_args(argv, baton):
28     usage = """usage: %prog summary version [ARGS] [APP]
29
30 Prints graphs of version usage in autoinstallers
31
32 Examples:
33     %prog summary list
34         Show graphs for all autoinstall versions
35     %prog summary list mediawiki
36         Show graph for MediaWiki autoinstall versions"""
37     parser = command.WizardOptionParser(usage)
38     baton.push(parser, "versions_path")
39     options, args = parser.parse_all(argv)
40     if len(args) > 1:
41         parser.error("too many arguments")
42     return options, args
43