]> scripts.mit.edu Git - wizard.git/blob - wizard/command/summary/version.py
Add support for a working dir in wizard.shell
[wizard.git] / wizard / command / summary / version.py
1 import math
2 import distutils.version
3
4 from wizard import app, command, deploy, util
5
6 def main(argv, baton):
7     options, str_show = parse_args(argv, baton)
8     HISTOGRAM_WIDTH = 30
9     if str_show:
10         apps = app.applications()
11         show = set(apps[x] for x in str_show)
12         accumulate = False
13     else:
14         str_show = []
15         show = set()
16         accumulate = True
17     c_application = {}
18     for d in deploy.parse_install_lines(str_show, options.versions_path):
19         c_application.setdefault(d.application, util.Counter())
20         version = truncate(d.app_version.version)
21         c_application[d.application].count(version)
22         if accumulate:
23             show.add(d.application)
24     if not show:
25         print "No applications found"
26     for application in show:
27         counter = c_application[application]
28         total = counter.sum()
29         print "%-20s %3d installs" % (application.name, total)
30         vmax = counter.max()
31         for version in sorted(counter.keys(), key=distutils.version.LooseVersion):
32             v = counter[version]
33             graph = '+' * int(math.ceil(float(v)/vmax * HISTOGRAM_WIDTH))
34             print "    %-16s %3d  %s" % (version, v, graph)
35         print
36
37 def truncate(version):
38     return str(version).partition('-scripts')[0]
39
40 def parse_args(argv, baton):
41     usage = """usage: %prog summary version [ARGS] [APP]
42
43 Prints graphs of version usage in autoinstallers
44
45 Examples:
46     %prog summary
47         Show graphs for all autoinstall versions
48     %prog summary version mediawiki
49         Show graph for MediaWiki autoinstall versions"""
50     parser = command.WizardOptionParser(usage)
51     baton.push(parser, "versions_path")
52     options, args = parser.parse_all(argv)
53     if len(args) > 1:
54         parser.error("too many arguments")
55     return options, args
56