6 from wizard import app, command, deploy, shell, util
9 options, show = parse_args(argv, baton)
11 application = app.applications()[appname]
13 deploys = deploy.parse_install_lines(show, options.versions_path)
18 deploys = itertools.islice(deploys, options.limit)
20 deploys = random.sample(list(deploys), options.sample)
23 logging.info("Processing " + d.location)
26 d.verifyTag(options.srv_path)
27 d.verifyGit(options.srv_path)
29 with util.ChangeDirectory(d.location):
31 out = sh.safeCall('git', 'diff', '--numstat', d.app_version.scripts_tag, strip=True)
33 for line in out.split("\n"):
34 added, deleted, filename = line.split(None, 3)
35 if filename.endswith("php.ini"): continue
36 if added == '-': continue
37 if deleted == '-': continue
39 deleted = int(deleted)
40 if not added and not deleted or application.researchFilter(filename, added, deleted):
42 results.append((added,deleted,filename))
43 if len(results) > options.filter:
44 print "- - " + d.location
49 for added,deleted,filename in results:
50 stats.setdefault(filename, 0)
52 if application.researchVerbose(filename) and not options.verbose:
54 print "%-7d %-7d %s/%s" % (added,deleted,d.location,filename)
55 except (deploy.NotConfiguredError, deploy.NotMigratedError):
56 # XXX: These should error, but for now don't
58 except (deploy.Error, shell.CallError):
59 # XXX: Maybe should also do app.Error
60 logging.error("%s in %s" % (traceback.format_exc(), d.location))
61 except KeyboardInterrupt:
64 logging.critical("%s in %s" % (traceback.format_exc(), d.location))
65 except KeyboardInterrupt:
67 print "Caught signal..."
70 for filename in sorted(stats.keys()):
71 count = stats[filename]
72 if not count: continue
73 print "%-7d %s" % (count, filename)
75 print "%d out of %d (%.1f%%) had large diffstats" % (iffy, total, float(iffy)/total*100)
76 print "%d out of %d (%.1f%%) had clean diffstats" % (clean, total, float(clean)/total*100)
78 def parse_args(argv, baton):
79 usage = """usage: %prog research APP
81 Tells you how spectacularly an upgrade here will explode."""
82 parser = command.WizardOptionParser(usage)
83 parser.add_option("--limit", dest="limit", type="int",
84 default=None, help="Limit the number of autoinstalls to look at.")
85 parser.add_option("--sample", dest="sample", type="int", metavar="N",
86 default=None, help="Instead of researching all installs, research a random sample of N size.")
87 parser.add_option("--filter", dest="filter", type="int", metavar="N",
88 default=4, help="How many files are permitted in a diffstat before treating the install as having a 'large diffstat'")
89 baton.push(parser, "srv_path")
90 baton.push(parser, "versions_path")
91 options, args = parser.parse_all(argv)
93 parser.error("too many arguments")
95 parser.error("must specify application to research")