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