Bug 1302192: (DO NOT LAND) graph-diffing script draft
authorDustin J. Mitchell <dustin@mozilla.com>
Thu, 22 Dec 2016 23:27:47 +0000
changeset 454194 81ec5bf5701a3735ff609dce1cb858c51300ada8
parent 454193 4cebe253a5222badd42b94aa52f9784295c70b45
child 454195 9e530a2503e671f65e94de8dc53bf0720484de04
push id39862
push userdmitchell@mozilla.com
push dateWed, 28 Dec 2016 14:40:33 +0000
bugs1302192
milestone53.0a1
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
graphdiff.py
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()