]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
detect existing packages correctly
authorHolger Levsen <holger@layer-acht.org>
Fri, 28 Sep 2012 19:03:59 +0000 (21:03 +0200)
committerHolger Levsen <holger@layer-acht.org>
Fri, 28 Sep 2012 19:03:59 +0000 (21:03 +0200)
db_add.py

index b7214635019bf3e5c06316a000cd7f40a2132a79..6176a2d832e8e8bf2c39c772f521791a5a10ef91 100755 (executable)
--- a/db_add.py
+++ b/db_add.py
@@ -131,12 +131,17 @@ def add_package_version(origin, package, version):
 
 def get_package_instance(origin, package, version):
     con = db_connect()
+    cur = con.cursor()
     try:
-        cur.execute("SELECT id FROM deb_package_instance"
+        cur.execute("SELECT deb_package_instance.id FROM deb_package_instance"
+                " JOIN deb_package ON (deb_package.id = deb_package_instance.deb_package_id)"
+                " JOIN deb_package_origin ON (deb_package_origin.id = deb_package_instance.deb_package_origin_id)"
+                " WHERE deb_package_origin.origin = '%s' AND deb_package.name = '%s' AND deb_package_instance.version = '%s'" % (origin, package, version))
+    except psycopg2.DatabaseError as e:
+        logger.debug("SELECT deb_package_instance.id FROM deb_package_instance"
                 " JOIN deb_package ON (deb_package.id = deb_package_instance.deb_package_id)"
                 " JOIN deb_package_origin ON (deb_package_origin.id = deb_package_instance.deb_package_origin_id)"
-                " WHERE origin = '%s' AND package = '%s' AND version = '%s'" % (origin, package, version))
-    except:
+                " WHERE deb_package_origin.origin = '%s' AND deb_package.name = '%s' AND deb_package_instance.version = '%s'" % (origin, package, version))
         return False
-    return cur.fetchone()[0]
-
+    if cur.fetchone():
+        return True