[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

[PATCH] Add a transition collision detector.



While this post-processing of generated HTML files is kind of ugly, it
makes it easy to show which transitions might be entangled due to
collisions.
---
 Makefile         |    2 +
 bin/tcd.py       |   70 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 media/revamp.css |    2 +-
 3 files changed, 73 insertions(+), 1 deletions(-)
 create mode 100755 bin/tcd.py

Little PoC with real examples on:
  http://release.debian.org/~kibi/transitions/html/audiofile.html

and friends. Maybe an “all packages involved” view would be nice, too.

diff --git a/Makefile b/Makefile
index 2a6ae0b..9f8b76d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,12 +1,14 @@
 
 BEN=/srv/release.debian.org/bin/ben
 OPT=-g /srv/release.debian.org/www/transitions/global.conf
+TCD=$(CURDIR)/bin/tcd.py
 
 all:
 	umask 0002; $(BEN) tracker $(OPT) -u
 
 update:
 	umask 0002; $(BEN) tracker $(OPT)
+	umask 0002; $(TCD)
 
 cron:
 	umask 0002; $(BEN) tracker $(OPT) -u -q
diff --git a/bin/tcd.py b/bin/tcd.py
new file mode 100755
index 0000000..4a04f0d
--- /dev/null
+++ b/bin/tcd.py
@@ -0,0 +1,70 @@
+#!/usr/bin/python
+# -*- coding: utf8 -*-
+# © 2012 Cyril Brulebois <kibi@debian.org>
+#
+# Transition collision detector
+
+import os
+import os.path
+import yaml
+
+PACKAGES   = 'export/packages.yaml'
+HTML_DIR   = 'html'
+MY_EXT     = '.tcd'
+MY_DIV     = 'id="tcd"'
+FOOTER_DIV = 'id="footer"'
+
+
+all_packages = yaml.load(open(PACKAGES, 'rb'))
+
+# Build a package→transitions dict:
+package_hits = {}
+for package in all_packages:
+  name = package['name']
+  if not package_hits.has_key(name):
+    package_hits[name] = []
+  for transition in package['list']:
+    if not transition[1] in ['permanent', 'finished']:
+      package_hits[name].append(transition[0])
+
+# Build a collisioner-package→transitions dict:
+results = {}
+for package in package_hits.keys():
+  if len(package_hits[package]) > 1:
+    print "Probable collision for: %s (%d)" % (package, len(package_hits[package]))
+    for hit in package_hits[package]:
+      print "  %s" % hit
+      if not results.has_key(hit):
+        results[hit] = []
+      results[hit].append((package, [x for x in package_hits[package] if x != hit]))
+
+# Post-process existing HTML files:
+for html in os.listdir(HTML_DIR):
+  if html.endswith('.html'):
+    transition = os.path.basename(html).replace('.html', '')
+    source_filename = os.path.join(HTML_DIR, html)
+    dest_filename   = os.path.join(HTML_DIR, html+MY_EXT)
+    source = open(source_filename, 'rb')
+    dest   = open(dest_filename, 'wb')
+    already_done = False
+    for line in source:
+      if line.find(MY_DIV) != -1:
+        already_done = True
+      if line.find(FOOTER_DIV) != -1 and not already_done:
+        dest.write('<!-- BEGIN: Added-by: TCD -->\n')
+        dest.write('<div %s><b>Collisions:</b>\n' % MY_DIV)
+        if results.has_key(transition):
+          dest.write('<ul>\n')
+          for package, transitions in results[transition]:
+            links = ['<a href="%s.html">%s</a>' % (x, x) for x in transitions]
+            dest.write('<li>%s → %s</li>\n' % (package, '&'.join(links)))
+          dest.write('</ul>\n')
+        else:
+          dest.write('<i>none</i>\n')
+        dest.write('</div>\n')
+        dest.write('<!-- END: Added-by: TCD -->\n')
+      dest.write(line)
+    source.close()
+    dest.close()
+    os.remove(source_filename)
+    os.rename(dest_filename, source_filename)
diff --git a/media/revamp.css b/media/revamp.css
index a215844..a51fc6f 100644
--- a/media/revamp.css
+++ b/media/revamp.css
@@ -65,7 +65,7 @@ h2#subtitle {
 }
 
 /* --- Content Pane --- */
-div#body {
+div#body, div#tcd {
     clear: both;
     border-top: 2px solid #d70751;
 /*    background: #dfdfdf;*/
-- 
1.7.2.5


Reply to: