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