]> err.no Git - dak/commitdiff
Move get_queue => get_or_set_queue
authorChris Lamb <lamby@debian.org>
Tue, 27 Oct 2009 21:57:08 +0000 (21:57 +0000)
committerChris Lamb <lamby@debian.org>
Tue, 27 Oct 2009 21:57:08 +0000 (21:57 +0000)
Signed-off-by: Chris Lamb <lamby@debian.org>
dak/process_unchecked.py
daklib/dbconn.py
daklib/queue.py

index 0645dd9f86d9fd45e633326c1626a8855aac46d8..48c3839b4dacb394e05a2c8465907edaa7cf5465 100755 (executable)
@@ -235,7 +235,7 @@ def package_to_queue(u, summary, short_summary, queue, perms=0660, build=True, a
     u.pkg.write_dot_dak(dir)
     u.move_to_dir(dir, perms=perms)
     if build:
-        get_queue(queue.lower()).autobuild_upload(u.pkg, dir)
+        get_or_set_queue(queue.lower()).autobuild_upload(u.pkg, dir)
 
     # Check for override disparities
     u.check_override()
index 56ff65aa9dc730cc1e9e40dcfd63fd649d4a2ff6..6d5497fc2d5f4b096d972631637e284eb2ce00aa 100755 (executable)
@@ -1464,9 +1464,10 @@ class Queue(object):
 __all__.append('Queue')
 
 @session_wrapper
-def get_queue(queuename, session=None):
+def get_or_set_queue(queuename, session=None):
     """
-    Returns Queue object for given C{queue name}.
+    Returns Queue object for given C{queue name}, creating it if it does not
+    exist.
 
     @type queuename: string
     @param queuename: The name of the queue
@@ -1482,11 +1483,17 @@ def get_queue(queuename, session=None):
     q = session.query(Queue).filter_by(queue_name=queuename)
 
     try:
-        return q.one()
+        ret = q.one()
     except NoResultFound:
-        return None
+        queue = Queue()
+        queue.queue_name = queuename
+        session.add(queue)
+        session.commit_or_flush()
+        ret = queue
+
+    return ret
 
-__all__.append('get_queue')
+__all__.append('get_or_set_queue')
 
 ################################################################################
 
index 4e5368770d52ff3565c34e7fe37469458155c7a0..cee15a5a451fbc9bc8f28464e29da0f8c542403f 100755 (executable)
@@ -1734,7 +1734,7 @@ distribution."""
         # <Ganneff> yes
 
         # This routine returns None on success or an error on failure
-        res = get_queue('accepted').autobuild_upload(self.pkg, cnf["Dir::Queue::Accepted"])
+        res = get_or_set_queue('accepted').autobuild_upload(self.pkg, cnf["Dir::Queue::Accepted"])
         if res:
             utils.fubar(res)