[Blends-commit] [Git][blends-team/blends][experimental] blends.py: Normalize "provides" column in UDD query

Ole Streicher gitlab at salsa.debian.org
Thu Apr 12 12:55:50 UTC 2018


Ole Streicher pushed to branch experimental at Debian Blends Team / blends


Commits:
41c7deb4 by Ole Streicher at 2018-04-12T14:55:43+02:00
blends.py: Normalize "provides" column in UDD query

- - - - -


1 changed file:

- blends.py


Changes:

=====================================
blends.py
=====================================
--- a/blends.py
+++ b/blends.py
@@ -771,27 +771,63 @@ def uddcache(packages, release, components=['main'], **db_args):
     Version = collections.namedtuple('Version',
                                      ('package', 'architecture', 'version'))
 
-    stmt = '''SELECT packages.package,
-                     packages.provides,
-                     packages.architecture,
-                     packages.version
-              FROM packages, releases
-              WHERE packages.release=releases.release
-                    AND (releases.release=%s  OR releases.role=%s)
-                    AND (packages.package IN %s OR packages.provides in %s)
-                    AND packages.component IN %s;'''
+    # To make the SELECT statements easier, we create a virtual view
+    # of the "packages" table that is restricted to the release and
+    # the component(s)
+    pkg_view_stmt = '''
+    CREATE TEMPORARY VIEW pkg
+    AS SELECT packages.package,
+           packages.version,
+           packages.architecture,
+           packages.provides
+    FROM packages, releases
+    WHERE packages.release=releases.release
+        AND (releases.release=%s  OR releases.role=%s)
+        AND packages.component IN %s;
+    '''
+
+    # Since the "provides" are in a comma separated list, we create a
+    # normalized view
+    provides_view_stmt = '''
+    CREATE TEMPORARY VIEW provides
+    AS SELECT DISTINCT
+        package,
+        version,
+        architecture,
+        regexp_split_to_table(provides, E',\\s*') AS provides
+    FROM pkg;
+    '''
+
+    # Query all packages that have one of the specified names either as
+    # package name, or as one of the provides
+    query_stmt = '''
+    SELECT package,
+           version,
+           architecture,
+           provides
+    FROM pkg
+    WHERE package IN %s
+    UNION
+    SELECT package,
+           version,
+           architecture,
+           provides
+    FROM provides
+    WHERE provides IN %s;
+    '''
 
     with psycopg2.connect(**db_args) as conn:
         cursor = conn.cursor()
-        cursor.execute(stmt, (release, release, pkgtuple, pkgtuple,
-                              componenttuple))
+        cursor.execute(pkg_view_stmt, (release, release, componenttuple))
+        cursor.execute(provides_view_stmt)
+        cursor.execute(query_stmt, (pkgtuple, pkgtuple))
 
         cache = dict()
-        for package, provides, arch, version in cursor:
+        for package, version, arch, provides in cursor:
             p = cache.setdefault(package, Package(package, []))
             p.versions.append(Version(p, arch, version))
             if provides:
-                pp = cache.setdefault(provides, Package(package, []))
-                pp.versions.append(Version(p, arch, version))
-
+                for prv in provides.split(','):
+                    pp = cache.setdefault(prv, Package(package, []))
+                    pp.versions.append(Version(p, arch, version))
         return cache



View it on GitLab: https://salsa.debian.org/blends-team/blends/commit/41c7deb4144113b28fbdbca92d8b87ea11177ef2

---
View it on GitLab: https://salsa.debian.org/blends-team/blends/commit/41c7deb4144113b28fbdbca92d8b87ea11177ef2
You're receiving this email because of your account on salsa.debian.org.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.alioth.debian.org/pipermail/blends-commit/attachments/20180412/9621fe91/attachment-0001.html>


More information about the Blends-commit mailing list