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