]> scripts.mit.edu Git - wizard.git/blob - lib/wizard/command/summary.py
Convert migrate to logger, and misc refactoring.
[wizard.git] / lib / wizard / command / summary.py
1 import optparse
2 import wizard.deploy as wd
3 import sys
4
5 class Printer(object):
6     def __init__(self, quiet, verbose):
7         self.i = 0
8         self.quiet = quiet
9         self.verbose = verbose
10         self.hanging = False
11     def tick(self):
12         self.i += 1
13         if not self.quiet and self.i % 10 == 0:
14             sys.stdout.write(".")
15             sys.stdout.flush()
16             self.hanging = True
17     def _hang(self):
18         if self.hanging:
19             self.hanging = False
20             print
21     def write(self, str = ""):
22         self._hang()
23         print str
24     def qwrite(self, str = ""):
25         if not self.quiet:
26             self._hang
27             print str
28     def tweet(self, str = ""):
29         if not self.quiet:
30             self._hang()
31             print str, # note comma
32     def chat(self, str = ""):
33         if self.verbose:
34             self._hang()
35             print str
36
37 def summary(argv, global_options):
38     usage = """usage: %prog summary [ARGS] APPS
39
40 Scans all of the collected data from parallel-find.pl, and
41 determines version histograms for our applications.  You may
42 optionally pass application parameters to filter the installs.
43
44 Examples:
45     %prog summary
46         Basic usage
47     %prog summary mediawiki
48         Displays only MediaWiki statistics
49     %prog summary -v -q mediawiki-1.2.3
50         Displays all deployments of this version"""
51     parser = optparse.OptionParser(usage)
52     parser.add_option("-v", "--verbose", dest="verbose", action="store_true",
53             default=False, help="Print interesting directories")
54     parser.add_option("-q", "--quiet", dest="quiet", action="store_true",
55             default=False, help="Suppresses progress output")
56     parser.add_option("--count-exists", dest="count_exists",
57             default=False, help="Count deployments that contain a file")
58     options, show = parser.parse_args(argv)
59     fi = wd.getInstallLines(global_options)
60     if not show: show = wd.applications.keys()
61     show = frozenset(show)
62     errors = 0
63     unrecognized = 0
64     processed = 0
65     printer = Printer(options.quiet, options.verbose)
66     printer.tweet("Processing")
67     for line in fi:
68         printer.tick()
69         try:
70             deploy = wd.Deployment.parse(line)
71         except wd.DeploymentParseError:
72             errors += 1
73             continue
74         except wd.NoSuchApplication:
75             unrecognized += 1
76             continue
77         name = deploy.getApplication().name
78         if name + "-" + str(deploy.getVersion()) in show:
79             printer.write("%s-%s deployment at %s" \
80                 % (name, deploy.getVersion(), deploy.location))
81         elif name in show:
82             pass
83         else:
84             continue
85         deploy.count()
86         if options.count_exists:
87             r = deploy.count_exists(options.count_exists)
88             if r:
89                 printer.chat("Found " + options.count_exists + " in " + deploy.location)
90     printer.write()
91     for app in wd.applications.values():
92         if app.name not in show: continue
93         printer.write(app.report())
94         printer.write()
95     printer.write("With %d errors and %d unrecognized applications" % (errors, unrecognized))
96