[Blends-commit] [SCM] website branch, master, updated. 7153f78f4b4be7d2a2430e566f558c51db560a55

Andreas Tille tille at debian.org
Wed May 15 08:36:18 UTC 2013


The following commit has been merged in the master branch:
commit 7153f78f4b4be7d2a2430e566f558c51db560a55
Author: Andreas Tille <tille at debian.org>
Date:   Wed May 15 10:32:01 2013 +0200

    Provide example how to read information about blends tasks into JSON format

diff --git a/misc/pts/taskinfo-example.py b/misc/pts/taskinfo-example.py
new file mode 100755
index 0000000..e974d0e
--- /dev/null
+++ b/misc/pts/taskinfo-example.py
@@ -0,0 +1,75 @@
+#!/usr/bin/python
+# Copyright 2013: Andreas Tille <tille at debian.org>
+# License: GPL
+
+#PORT=5441
+UDDPORT=5452
+PORT=UDDPORT
+DEFAULTPORT=5432
+
+from sys import stderr, exit
+import psycopg2
+import json
+
+
+###########################################################################################
+# Define several prepared statements to query UDD
+try:
+  conn = psycopg2.connect(host="localhost",port=PORT,user="guest",database="udd")
+except psycopg2.OperationalError, err:
+  try:
+    conn = psycopg2.connect(host="udd.debian.org",port=UDDPORT,user="guest",database="udd")
+  except psycopg2.OperationalError, err:
+    # logger not known at this state: logger.warning
+    print >>stderr, "PostgreSQL does not seem to run on port %i .. trying default port %i.\n\tMessage: %s" % (PORT, DEFAULTPORT, str(err))
+    try:
+        conn = psycopg2.connect(host="localhost",port=DEFAULTPORT,user="guest",database="udd")
+    except psycopg2.OperationalError:
+	# Hmmm, I observed a really strange behaviour on one of my machines where connecting to
+	# localhost does not work but 127.0.0.1 works fine.  No idea why ... but this should
+	# do the trick for the moment
+	conn = psycopg2.connect(host="127.0.0.1",port=DEFAULTPORT,user="guest",database="udd")
+
+curs = conn.cursor()
+# uddlog = open('logs/uddquery.log', 'w')
+
+def _execute_udd_query(query):
+    try:
+        curs.execute(query)
+    except psycopg2.ProgrammingError, err:
+        print >>stderr, "Problem with query\n%s" % (query)
+        print >>stderr, err
+        exit(-1)
+    except psycopg2.DataError, err:
+        print >>stderr, "%s; query was\n%s" % (err, query)
+
+def RowDictionaries(cursor):
+    """Return a list of dictionaries which specify the values by their column names"""
+
+    description = cursor.description
+    if not description:
+        # even if there are no data sets to return the description should contain the table structure.  If not something went
+        # wrong and we return NULL as to represent a problem
+        return NULL
+    if cursor.rowcount <= 0:
+        # if there are no rows in the cursor we return an empty list
+        return []
+
+    data = cursor.fetchall()
+    result = []
+
+    for row in data:
+        resultrow = {}
+        i = 0
+        for dd in description:
+            resultrow[dd[0]] = row[i]
+            i += 1
+        result.append(resultrow)
+    return result
+
+query = "SELECT blend, task, package, dependency, component FROM blends_dependencies WHERE distribution = 'debian'"
+_execute_udd_query(query)
+if curs.rowcount > 0:
+    data_in_json_format = json.dumps(RowDictionaries(curs))
+
+print data_in_json_format

-- 
Static and dynamic websites for Debian Pure Blends



More information about the Blends-commit mailing list