]> Frank Brehm's Git Trees - profitbricks/jenkins-build-scripts.git/commitdiff
rewrite into a function
authorHolger Levsen <holger@layer-acht.org>
Wed, 26 Sep 2012 09:53:53 +0000 (11:53 +0200)
committerHolger Levsen <holger@layer-acht.org>
Wed, 26 Sep 2012 09:53:53 +0000 (11:53 +0200)
add_liveboot_request.py
debian_build.py

index 1fd4f5cae18626fcb39221b187efc0fce1bd7cc8..a3fad104bf0beac808c8bf05a3f05db4a15073e7 100644 (file)
@@ -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
index 34a61c74ca462fe174e1dbaac0f1f3387a6f915e..df2523c19c531e992f417a2f926a7eb9017f7031 100755 (executable)
@@ -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()