From 36e207c501e42b43a8c94c9d1d6ad54848728a5f Mon Sep 17 00:00:00 2001 From: Holger Levsen Date: Wed, 26 Sep 2012 17:38:42 +0200 Subject: [PATCH] adapt to new db layout --- debian_build.py | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/debian_build.py b/debian_build.py index 7aac027..7535511 100755 --- a/debian_build.py +++ b/debian_build.py @@ -137,14 +137,24 @@ def db_add_job(con, name): #logger.debug("INSERT INTO jenkins_job(name) VALUES('%s')" % (name)) return cur.fetchone()[0] -def db_add_build(con, number, db_id, start, end): +def db_add_build(con, number, db_id): cur = con.cursor() cur.execute("SAVEPOINT a") try: - cur.execute("INSERT INTO jenkins_build(jenkins_build_number, jenkins_job_id, build_start, build_end, successful) VALUES(%s, %s, '%s', '%s', %s) RETURNING id" % (number, db_id, start, end, 'true')) + cur.execute("INSERT INTO jenkins_build(jenkins_build_number, jenkins_job_id VALUES(%s, %s) RETURNING id" % (number, db_id)) except psycopg2.DatabaseError as e: cur.execute("ROLLBACK TO a") # have to rollback after failed command - #logger.debug("INSERT INTO jenkins_build(jenkins_build_number, jenkins_job_id, build_start, build_end, successful) VALUES(%s, %s, '%s', '%s', %s) RETURNING id" % (number, db_id, start, end, 'true')) + #logger.debug("INSERT INTO jenkins_build(jenkins_build_number, jenkins_job_id VALUES(%s, %s) RETURNING id" % (number, db_id)) + return cur.fetchone()[0] + +def db_add_build_result(con, number, start, end): + cur = con.cursor() + cur.execute("SAVEPOINT a") + try: + cur.execute("INSERT INTO jenkins_build_result(jenkins_build_number, build_start, build_end, successful) VALUES(%s, '%s', '%s', %s) RETURNING id" % (number, start, end, 'true')) + except psycopg2.DatabaseError as e: + cur.execute("ROLLBACK TO a") # have to rollback after failed command + #logger.debug("INSERT INTO jenkins_build_result(jenkins_build_number, build_start, build_end, successful) VALUES(%s, '%s', '%s', %s) RETURNING id" % (number, start, end, 'true')) return cur.fetchone()[0] def db_add_package(con, package): @@ -189,7 +199,9 @@ def add_package_instance(origin, job_name, build_number, changes_file, version, #logger.debug("INSERT success origin %s" % origin) db_job_id = db_add_job(con, job_name) #logger.debug("INSERT success job %s" % job_name) - db_build_id = db_add_build (con, build_number, db_job_id, start, end) + # maybe FIXME: we could add the build already once its started, but for package builds we dont wanna add failures to the db at all + db_build_id = db_add_build (con, build_number, db_job_id) + db_build_result_id = db_add_build_result (con, build_number, start, end) #logger.debug("INSERT success build number %s" % build_number) #logger.debug("processing %s" %(changes_file)) cmd = ["dcmd", '--deb', changes_file] @@ -209,7 +221,7 @@ def add_package_instance(origin, job_name, build_number, changes_file, version, #logger.debug('package: %s' %(package)) db_package_id = db_add_package (con, package) #logger.debug("INSERT success package %s" % package) - db_add_package_instance (con, db_package_id, db_origin_id, db_build_id, version) + db_add_package_instance (con, db_package_id, db_origin_id, db_build_result_id, version) logger.debug("INSERT success package version %s %s" %( package,version)) #logger.debug('Cmd returned with status %d' %(cmdobj.returncode)) con.commit() -- 2.39.5