From: Holger Levsen Date: Fri, 28 Sep 2012 19:03:59 +0000 (+0200) Subject: detect existing packages correctly X-Git-Url: https://git.uhu-banane.de/?a=commitdiff_plain;h=e60ace9cc9d65057b108421188bf3e821c9061bc;p=profitbricks%2Fjenkins-build-scripts.git detect existing packages correctly --- diff --git a/db_add.py b/db_add.py index b721463..6176a2d 100755 --- 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