7 from wizard import command, deploy, shell, util
10 options, show = parse_args(argv, baton)
12 deploys = deploy.parse_install_lines(show, options.versions_path)
17 deploys = itertools.islice(deploys, options.limit)
19 deploys = random.sample(list(deploys), options.sample)
22 logging.info("Processing " + d.location)
25 d.verifyTag(options.srv_path)
26 d.verifyGit(options.srv_path)
28 with util.ChangeDirectory(d.location):
30 out = sh.safeCall('git', 'diff', '--numstat', d.app_version.scripts_tag, strip=True)
32 for line in out.split("\n"):
33 added, deleted, filename = line.split(None, 3)
34 if filename.endswith("php.ini"): continue
35 if added == '-': continue
36 if deleted == '-': continue
38 deleted = int(deleted)
40 if filename == "LocalSettings.php":
41 if added == deleted == 10:
43 elif added == deleted == 9:
45 elif filename == "AdminSettings.php":
46 if added == 0 and deleted == 20:
48 elif filename == "config/index.php" or filename == "config/index.php5":
51 if not added and not deleted:
53 results.append((added,deleted,filename))
54 if len(results) > options.filter:
55 print "- - " + d.location
60 for added,deleted,filename in results:
61 stats.setdefault(filename, 0)
64 if filename == "LocalSettings.php" and not options.verbose:
66 print "%-7d %-7d %s/%s" % (added,deleted,d.location,filename)
67 except (deploy.NotConfiguredError, deploy.NotMigratedError):
68 # XXX: These should error, but for now don't
70 except (deploy.Error, shell.CallError):
71 logging.error("%s in %s" % (traceback.format_exc(), d.location))
72 except KeyboardInterrupt:
75 logging.critical("%s in %s" % (traceback.format_exc(), d.location))
76 except KeyboardInterrupt:
78 print "Caught signal..."
81 for filename in sorted(stats.keys()):
82 count = stats[filename]
83 if not count: continue
84 print "%-7d %s" % (count, filename)
86 print "%d out of %d (%.1f%%) had large diffstats" % (iffy, total, float(iffy)/total*100)
87 print "%d out of %d (%.1f%%) had clean diffstats" % (clean, total, float(clean)/total*100)
89 def parse_args(argv, baton):
90 usage = """usage: %prog research APP
92 Tells you how spectacularly an upgrade here will explode."""
93 parser = command.WizardOptionParser(usage)
94 parser.add_option("--limit", dest="limit", type="int",
95 default=None, help="Limit the number of autoinstalls to look at.")
96 parser.add_option("--sample", dest="sample", type="int", metavar="N",
97 default=None, help="Instead of researching all installs, research a random sample of N size.")
98 parser.add_option("--filter", dest="filter", type="int", metavar="N",
99 default=4, help="How many files are permitted in a diffstat before treating the install as having a 'large diffstat'")
100 baton.push(parser, "srv_path")
101 baton.push(parser, "versions_path")
102 options, args = parser.parse_all(argv)
104 parser.error("too many arguments")
106 parser.error("must specify application to research")