#logger.debug("INSERT INTO jenkins_build_result(jenkins_build_id, build_start, build_end, successful) VALUES(%s, '%s', '%s', %s) RETURNING id" % (build_id, start, end, 'true'))
return cur.fetchone()[0]
+def db_add_origin(con, origin):
+ cur = con.cursor()
+ cur.execute("SAVEPOINT a")
+ try:
+ cur.execute("INSERT INTO deb_package_origin(origin) VALUES('%s') RETURNING id" % (origin))
+ except psycopg2.DatabaseError as e:
+ # record already exist
+ cur.execute("ROLLBACK TO a") # have to rollback after failed command
+ cur.execute("SELECT id FROM deb_package_origin WHERE origin='%s'" % (origin))
+ #logger.debug("INSERT INTO deb_package_origin(origin) VALUES('%s') RETURNING id" % (origin))
+ return cur.fetchone()[0]
+
def db_add_package(con, package):
cur = con.cursor()
cur.execute("SAVEPOINT a")
try:
cur.execute("INSERT INTO deb_package_instance(deb_package_id, deb_package_origin_id, jenkins_build_result_id, version, available) VALUES(%s, %s, %s, '%s', 'true') RETURNING id" % (package_id, origin_id, build_result_id, version))
except psycopg2.DatabaseError as e:
- # record already exist - this MUST NOT HAPPEN
+ # record already exist - this MUST NOT HAPPEN for jenkins builds
cur.execute("ROLLBACK TO a") # have to rollback after failed command
logger_error("FAILED: INSERT INTO deb_package_instance(deb_package_id, deb_package_origin_id, jenkins_build_result_id, version, available) VALUES(%s, %s, %s, '%s', 'true') RETURNING id" % (package_id, origin_id, build_result_id, version))
exit_error()
return cur.fetchone()[0]
-def db_add_origin(con, origin):
- cur = con.cursor()
- cur.execute("SAVEPOINT a")
- try:
- cur.execute("INSERT INTO deb_package_origin(origin) VALUES('%s') RETURNING id" % (origin))
- except psycopg2.DatabaseError as e:
- # record already exist
- cur.execute("ROLLBACK TO a") # have to rollback after failed command
- cur.execute("SELECT id FROM deb_package_origin WHERE origin='%s'" % (origin))
- #logger.debug("INSERT INTO deb_package_origin(origin) VALUES('%s') RETURNING id" % (origin))
- return cur.fetchone()[0]
-
-def add_package_instance(origin, job_name, build_number, changes_file, version, start, end):
+def add_package_instances(origin, job_name, build_number, changes_file, version, start, end):
con = db_connect()
#logger.debug("save %s to database" %(job_name))
db_origin_id = db_add_origin(con, origin)
)
#logger.debug('Calling "%s":' %(' '.join(cmd)))
ret = cmdobj.wait()
+ db_package_instance_ids=[]
for line in cmdobj.stdout.readlines():
package = os.path.basename(line.strip()).split('_')[0]
#logger.debug('package: %s' %(package))
db_package_id = db_add_package (con, package)
#logger.debug("INSERT success package %s" % package)
- db_package_instance_id = db_add_package_instance (con, db_package_id, db_origin_id, db_build_result_id, version)
+ db_package_instance_ids.append(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()
logger.info("CIDB update OK.")
- return db_package_instance_id
+ return db_package_instance_ids
def add_package_version(origin, package, version):
logger = logger_init()
db_origin_id = db_add_origin(con, origin)
db_package_id = db_add_package (con, package)
db_package_instance_id = db_add_package_instance (con, db_package_id, db_origin_id, 'NULL', version)
- logger.debug("INSERT success package version %s %s" %( package,version))
- #logger.debug('Cmd returned with status %d' %(cmdobj.returncode))
con.commit()
return db_package_instance_id