--- /dev/null
+#!/usr/bin/env python
+
+"""
+This script generates basic statistics about our autoinstalls.
+"""
+
+import os
+import optparse
+import fileinput
+import math
+from distutils.version import LooseVersion as Version
+
+class ApplicationStatistic(object):
+ MAXBAR = 18
+ def __init__(self, name):
+ self.name = name
+ self.data = {}
+ self.total = 0
+ def count(self, version):
+ self.total += 1
+ if version in self.data:
+ self.data[version] += 1
+ else:
+ self.data[version] = 1
+ def _graph(self, v):
+ return '+' * int(math.ceil(float(v) / self.total * self.MAXBAR))
+ def __str__(self):
+ if not self.data: return self.name + " (no installs)"
+ ret = [self.name] + \
+ [" %-8s %3d %s" % (v,c,self._graph(c)) for v,c in
+ sorted(
+ self.data.items(),
+ lambda x, y: cmp(Version(x[0]), Version(y[0])))]
+ return "\n".join(ret)
+
+def main():
+ usage = "usage: %prog [options] [application]"
+ parser = optparse.OptionParser(usage)
+ parser.add_option("-v", "--version-dir", dest="version_dir",
+ default="/afs/athena.mit.edu/contrib/scripts/sec-tools/store/versions",
+ help="Location of parallel-find output")
+ options, applications = parser.parse_args()
+ if not applications:
+ # This is hard-coded: it might be better to have a central
+ # list of these somewhere and read it out here
+ applications = ["mediawiki", "wordpress", "joomla", "e107", "gallery2",
+ "phpBB", "advancedbook", "phpical", "trac", "turbogears", "django"]
+ appHash = dict([(n,ApplicationStatistic(n)) for n in applications ])
+ vd = options.version_dir
+ try:
+ fi = fileinput.input([vd + "/" + f for f in os.listdir(vd)])
+ except OSError:
+ print "No permissions; check if AFS is mounted"
+ raise SystemExit(-1)
+ for line in fi:
+ print line
+ try:
+ location, deploydir = line.rstrip().split(":")
+ application, version = deploydir.split("/")[-1].split("-")
+ except ValueError:
+ # old style .scripts-version
+ # not going to bother for now
+ continue
+ if application not in appHash: continue
+ appHash[application].count(version)
+ for stat in appHash.values():
+ print stat
+ print
+
+if __name__ == "__main__":
+ main()
+