[Collab-qa-commits] r2026 - udd/web/cgi-bin

Stefano Rivera stefanor at alioth.debian.org
Tue Sep 20 08:41:27 UTC 2011


Author: stefanor
Date: 2011-09-20 08:41:27 +0000 (Tue, 20 Sep 2011)
New Revision: 2026

Modified:
   udd/web/cgi-bin/bug-blockers.cgi
Log:
bug-blockers.cgi: Show bug title, and UDD data freshness

Modified: udd/web/cgi-bin/bug-blockers.cgi
===================================================================
--- udd/web/cgi-bin/bug-blockers.cgi	2011-09-19 22:38:13 UTC (rev 2025)
+++ udd/web/cgi-bin/bug-blockers.cgi	2011-09-20 08:41:27 UTC (rev 2026)
@@ -19,7 +19,13 @@
 
 import psycopg2
 
+DATABASE = {'database': 'udd',
+            'port': 5441,
+            'host': 'localhost',
+            'user': 'guest',
+           }
 
+
 class AttrDict(dict):
     def __init__(self, **kwargs):
         for key, value in kwargs.iteritems():
@@ -32,10 +38,7 @@
             raise AttributeError(e)
 
 
-def find_blockers(bug):
-    conn = psycopg2.connect(database='udd', port=5441, host='localhost',
-                            user='guest')
-    cur = conn.cursor()
+def find_blockers(cur, bug):
     cur.execute("""
     SELECT bugs.id, bugs.source, bugs.severity, bugs.title, bugs.last_modified,
            bugs.affects_testing,
@@ -77,10 +80,19 @@
 
         yield b
 
-    cur.close()
-    conn.close()
 
-result_template="""
+def last_updated(cur):
+    cur.execute("SELECT MAX(start_time) FROM timestamps "
+                "WHERE source = 'bugs' AND command = 'run'")
+    return cur.fetchone()[0]
+
+
+def bug_title(cur, bug):
+    cur.execute("SELECT title FROM bugs WHERE id = %s", (bug,))
+    return cur.fetchone()[0]
+
+
+result_template = """
 <!DOCTYPE html>
 <html>
 <head>
@@ -103,13 +115,17 @@
         td.severity-serious, td.severity-grave, td.severity-critical {
             color: red;
         }
-        td.severity-important, td.severity-serious, td.severity-grave, td.severity-critical {
+        td.severity-important, td.severity-serious, td.severity-grave,
+        td.severity-critical {
             font-weight: bold;
         }
     </style>
 </head>
 <body>
-<h1>Bugs Blocking <a href="http://bugs.debian.org/%(bug)s">#%(bug)s</a></h1>
+<h1>
+    Bugs Blocking <a href="http://bugs.debian.org/%(bug)s">#%(bug)s</a>:
+    %(bug_title)s
+</h1>
 <table border="1" class="sortable">
     <thead>
         <tr>
@@ -126,11 +142,12 @@
 %(table)s
     </tbody>
 </table>
+<p>UDD's Debian BTS data last updated: %(updated)s UTC</p>
 </body>
 </html>
 """.strip()
 
-table_template="""
+table_template = """
         <tr class="%(class)s">
             <td><a href="http://bugs.debian.org/%(id)s">%(id)s</a></td>
             <td><a href="http://packages.qa.debian.org/%(source)s">%(source)s</a></td>
@@ -161,9 +178,12 @@
 </html>
 """.strip()
 
+
 def render_blockers(bug):
+    conn = psycopg2.connect(**DATABASE)
+    cursor = conn.cursor()
     table = []
-    for blocker in find_blockers(bug):
+    for blocker in find_blockers(cursor, bug):
         subst = {
             'class': blocker.attrs['class'],
             'id': blocker.id,
@@ -177,13 +197,19 @@
         table.append(table_template % subst)
     subst = {
         'bug': bug,
+        'bug_title': bug_title(cursor, bug),
         'table': ''.join(table),
+        'updated': last_updated(cursor).strftime('%Y-%m-%d %H:%M'),
     }
+    cursor.close()
+    conn.close()
     sys.stdout.write(result_template % subst)
 
+
 def render_form():
     sys.stdout.write(form_html)
 
+
 def main():
     print 'Content-Type: text/html; charset=utf-8'
     print ''




More information about the Collab-qa-commits mailing list