From: Edward Z. Yang Date: Mon, 18 May 2009 21:48:19 +0000 (-0400) Subject: Add a nice install-statistics script. X-Git-Url: https://scripts.mit.edu/gitweb/wizard.git/commitdiff_plain/6c691e1e75de8733eab04dc3557dff96081aab22 Add a nice install-statistics script. Signed-off-by: Edward Z. Yang --- diff --git a/bin/install-statistics b/bin/install-statistics new file mode 100755 index 0000000..6fd67b0 --- /dev/null +++ b/bin/install-statistics @@ -0,0 +1,72 @@ +#!/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() +