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

Ole Streicher olebole at debian.org
Wed Apr 27 11:19:50 UTC 2016


The following commit has been merged in the master branch:
commit a4a1935750ff73446217913e7f622f1d2cc0d135
Author: Ole Streicher <olebole at debian.org>
Date:   Wed Apr 27 13:18:34 2016 +0200

    Make tasks.py and blendstasktools.py fully Python 3 compatible

diff --git a/webtools/blendstasktools.py b/webtools/blendstasktools.py
index 148e0f4..1b2fcc3 100644
--- a/webtools/blendstasktools.py
+++ b/webtools/blendstasktools.py
@@ -289,6 +289,7 @@ except psycopg2.OperationalError as err:
             # do the trick for the moment
             conn = psycopg2.connect(host="127.0.0.1", port=DEFAULTPORT,
                                     user="guest", database="udd")
+conn.set_client_encoding('utf-8')
 
 curs = conn.cursor()
 # uddlog = open('logs/uddquery.log', 'w')
@@ -643,15 +644,21 @@ def RowDictionaries(cursor):
     """Return a list of dictionaries which specify the values by their column names"""
 
     if not cursor.description:
-        # even if there are no data sets to return the description should contain the table structure.  If not something went
+        # even if there are no data sets to return the description
+        # should contain the table structure.  If not something went
         # wrong and we return None as to represent a problem
         return None
 
-    return [dict((dd[0],
-                  unicode(dv.decode('utf-8')) if isinstance(dv, str) else dv)
-                 for (dd, dv) in zip(cursor.description, row))
-            for row in cursor]
-
+    try:
+        return [dict((dd[0],
+                      unicode(dv.decode('utf-8')) if isinstance(dv, str)
+                      else dv)
+                     for (dd, dv) in zip(cursor.description, row))
+                for row in cursor]
+    
+    except NameError: # Python 3
+        return [dict((dd[0], dv) for (dd, dv) in zip(cursor.description, row))
+                for row in cursor]
 
 def BrowserFromVcsURL(vcs_type, vcs_url):
     # Guess Vcs-Browser URL from VCS URL
@@ -723,14 +730,6 @@ class DependantPackage:
         self.properties['version'] = []  # list of {'release', 'version', 'archs'} dictionary containing version and architecture information
         self.properties['desc'] = {'en': {}}  # An English description should be available in any case
 
-    # sort these objects according to the package name
-    def __cmp__(self, other):
-        # Comparing with None object has to return something reasonable
-        if other is None:
-            return -2
-        # Sort according to package name
-        return cmp(self.properties['name'], other.properties['name'])
-
     def __str__(self):
         ret = "pkg:"    + self.properties['name']
         for prop in self.properties:
@@ -876,17 +875,13 @@ class Tasks:
         if hastranslations > 0:
             query = "EXECUTE query_metapkg_trans('%s')" % List2PgArray(metapackages)
             _execute_udd_query(query)
-            if curs.rowcount > 0:
-                for row in RowDictionaries(curs):
-                    metapkg_translations[row['package']] = row
+            for row in RowDictionaries(curs):
+                metapkg_translations[row['package']] = row
 
         for task in self.metapackagekeys:
             td = TaskDependencies(self.blendname, task=task, tasksdir=self.tasksdir)
             pkgname = prefix + task
-            translations = None
-            if pkgname in metapkg_translations:
-                translations = metapkg_translations[pkgname]
-            td.SetMetapackageInfo(pkgname, translations)
+            td.SetMetapackageInfo(pkgname, metapkg_translations.get(pkgname))
             logger.debug("Task : %s " % task)
             if td.GetTaskDependencies(source):
                 self.tasks[task] = td
@@ -1692,7 +1687,7 @@ class TaskDependencies:
                         del dep.properties['wnpp']
 
         for dependency in self.dependencies.keys():
-            self.dependencies[dependency].sort()
+            self.dependencies[dependency].sort(key = lambda x: x.properties['name'])
         return 1  # Success
 
     def getPackageNames(self, sections):
@@ -1806,7 +1801,7 @@ class TaskDependencies:
                     logger.warning("Dependency with unknown status: %s (Task %s)" % (dep.properties['name'], self.task))
 
         for dependency in self.dependencies.values():
-            dependency.sort()
+            dependency.sort(key = lambda x: x.properties['name'])
 
     def __str__(self):
         ret = "Blend: " + self.blendname + ", " \
diff --git a/webtools/blendstasktools_udd.py b/webtools/blendstasktools_udd.py
index 60958e6..36b9e6e 100644
--- a/webtools/blendstasktools_udd.py
+++ b/webtools/blendstasktools_udd.py
@@ -268,7 +268,6 @@ def GetDependencies2Use(dependencystatus=[], max_order='prospective'):
 # Define several prepared statements to query UDD
 try:
     conn = psycopg2.connect(host="localhost",port=PORT,user="guest",database="udd")
-    conn.set_client_encoding('utf-8')
 except psycopg2.OperationalError as err:
   try:
     conn = psycopg2.connect("service=udd")
@@ -283,6 +282,7 @@ except psycopg2.OperationalError as err:
 	    # do the trick for the moment
 	    conn = psycopg2.connect(host="127.0.0.1",port=DEFAULTPORT,user="guest",database="udd")
 
+conn.set_client_encoding('utf-8')
 curs = conn.cursor()
 # uddlog = open('logs/uddquery.log', 'w')
 
@@ -587,10 +587,16 @@ def RowDictionaries(cursor):
         # wrong and we return None as to represent a problem
         return None
 
-    return [dict((dd[0],
-                  unicode(dv.decode('utf-8')) if isinstance(dv, str) else dv)
-                 for (dd, dv) in zip(cursor.description, row))
-            for row in cursor]
+    try:
+        return [dict((dd[0],
+                      unicode(dv.decode('utf-8')) if isinstance(dv, str)
+                      else dv)
+                     for (dd, dv) in zip(cursor.description, row))
+                for row in cursor]
+    
+    except NameError: # Python 3
+        return [dict((dd[0], dv) for (dd, dv) in zip(cursor.description, row))
+                for row in cursor]
 
 
 def BrowserFromVcsURL(vcs_type, vcs_url):
diff --git a/webtools/tasks.py b/webtools/tasks.py
index a2b1ceb..097e3ce 100755
--- a/webtools/tasks.py
+++ b/webtools/tasks.py
@@ -80,7 +80,10 @@ use_dependencystatus = GetDependencies2Use()
 for lang in languages:
     htafp.write("AddLanguage {htaccess} .{ddtp}\n".format(**lang))
     l10nstring[lang['ddtp']].install()
-    _ = l10nstring[lang['ddtp']].ugettext
+    try:
+        _ = l10nstring[lang['ddtp']].ugettext
+    except AttributeError: # Python 3
+        _ = l10nstring[lang['ddtp']].gettext
     data['lang']              = lang['ddtp']
     data['license']           = _('License')
     data['version']           = _('Version')
diff --git a/webtools/tasks_udd.py b/webtools/tasks_udd.py
index 2fe47de..40f0ff5 100755
--- a/webtools/tasks_udd.py
+++ b/webtools/tasks_udd.py
@@ -80,7 +80,10 @@ use_dependencystatus = GetDependencies2Use()
 for lang in languages:
     htafp.write("AddLanguage {htaccess} .{ddtp}\n".format(**lang))
     l10nstring[lang['ddtp']].install()
-    _ = l10nstring[lang['ddtp']].ugettext
+    try:
+        _ = l10nstring[lang['ddtp']].ugettext
+    except AttributeError: # Python 3
+        _ = l10nstring[lang['ddtp']].gettext
     data['lang']              = lang['ddtp']
     data['license']           = _('License')
     data['version']           = _('Version')

-- 
Static and dynamic websites for Debian Pure Blends



More information about the Blends-commit mailing list