Bug 1302192: (DO NOT LAND) graph-diffing script
This was necessary since I was changing labels -- without it, the diffs were
meaningless because the order of the tasks changed.
MozReview-Commit-ID: IbK7TJM7n4y
new file mode 100644
--- /dev/null
+++ b/graphdiff.py
@@ -0,0 +1,59 @@
+import json
+import difflib
+import re
+
+def tests_only(graph):
+ return {l: t for l, t in graph.iteritems()
+ if t['attributes'].get('legacy_kind', '').endswith('test') or t['attributes']['kind'] in ('desktop-test', 'android-test', 'test')}
+
+def replace_labels(str):
+ return re.sub("<[^>]*>", "<...>", str)
+
+def drop_stuff(graph):
+ for t in graph.itervalues():
+ del t['label']
+ del t['attributes']['kind']
+ del t['task']['metadata']
+ return graph
+
+def relabel(graph):
+ rv = {}
+ for l, t in graph.iteritems():
+ if l.startswith('android-test-') or l.startswith('desktop-test-'):
+ l = l[8:]
+ if l in rv:
+ raise Exception("duplicate label %s for %s / %s" % (l, t['label'], rv[l]['label']))
+ rv[l] = t
+ return rv
+
+def main():
+ graph1 = json.load(open("before"))
+ graph2 = json.load(open("after"))
+
+ graph1 = drop_stuff(relabel(tests_only(graph1)))
+ graph2 = drop_stuff(relabel(tests_only(graph2)))
+
+ print("comparing {} and {} tasks".format(len(graph1), len(graph2)))
+
+ only1 = set(graph1) - set(graph2)
+ only2 = set(graph2) - set(graph1)
+ for task in sorted(only1 | only2):
+ if task in only1:
+ print "-" + task
+ del graph1[task]
+ else:
+ print "+" + task
+ del graph2[task]
+
+ graph1 = replace_labels(json.dumps(graph1, indent=4, sort_keys=True)).split('\n')
+ graph2 = replace_labels(json.dumps(graph2, indent=4, sort_keys=True)).split('\n')
+
+ diff = False
+ for line in difflib.unified_diff(graph1, graph2, fromfile="before", tofile="after", lineterm='', n=4):
+ diff = True
+ print line
+
+ if not diff:
+ print("no diff")
+
+main()