From 114f92cb766e91e837bc35df48d5bb268d3cb1cc Mon Sep 17 00:00:00 2001 From: Holger Levsen Date: Wed, 26 Sep 2012 11:53:53 +0200 Subject: [PATCH] rewrite into a function --- add_liveboot_request.py | 28 ++++++++-------------------- debian_build.py | 3 ++- 2 files changed, 10 insertions(+), 21 deletions(-) diff --git a/add_liveboot_request.py b/add_liveboot_request.py index 1fd4f5c..a3fad10 100644 --- a/add_liveboot_request.py +++ b/add_liveboot_request.py @@ -82,18 +82,12 @@ def update_default_package_list(con, def_package_list_id, return(True and result) -def add_liveboot_request(con, owner_uid, package_list_id): +def insert_liveboot_request(con, owner_uid, package_list_id): cur = con.cursor() cur.execute("INSERT INTO liveboot_request(owner_uid, package_list_id)" " VALUES(%s)", (owner_uid, package_list_id)) - -if __name__ == "__main__": - if len(sys.argv) != 2: - print("usage: %s deb_package_instance_id") - sys.exit(1) - deb_pkg_instance_id = int(sys.argv[1]) - +def add_liveboot_request(deb_pkg_instance_id): logging.basicConfig() logger = logging.getLogger() @@ -101,12 +95,7 @@ if __name__ == "__main__": # If the package is included in the default package list, update the list # to include newest version of the package deb_pkg_id = get_deb_pkg_id(con, deb_pkg_instance_id) - if not deb_pkg_id: - sys.exit(1) - def_pkg_list_id = get_default_pkg_list(con) - if not def_pkg_list_id: - sys.exit(1) # This can't return None with the used db constraints deb_pkg_instance_ids = get_deb_pkg_instance_ids(con, deb_pkg_id) @@ -119,10 +108,9 @@ if __name__ == "__main__": if not updated: logger.info("deb_package with id %s doesn't exist in default package" " list, no liveboot request will be created") - sys.exit(0) - - # create a new liveboot request with the updated default package list - jenkins_uid = pwd.getpwnam("jenkins").pw_uid - add_liveboot_request(con, jenkins_uid, def_pkg_list_id) - con.commit() - sys.exit(0) + else: + # create a new liveboot request with the updated default package list + jenkins_uid = pwd.getpwnam("jenkins").pw_uid + insert_liveboot_request(con, jenkins_uid, def_pkg_list_id) + con.commit() + return diff --git a/debian_build.py b/debian_build.py index 34a61c7..df2523c 100755 --- a/debian_build.py +++ b/debian_build.py @@ -690,7 +690,8 @@ if __name__ == '__main__': subprocess.check_call(cmd) #FIXME: this should really cause an error # exit_error() - add_liveboot_request(package_instance_id) + add_liveboot_request(package_instance_id): + # finally exit_ok() -- 2.39.5