From 852b95bdefa52aead80cad3a51381535774dc48a Mon Sep 17 00:00:00 2001 From: Chris Lamb Date: Tue, 27 Oct 2009 21:57:08 +0000 Subject: [PATCH] Move get_queue => get_or_set_queue Signed-off-by: Chris Lamb --- dak/process_unchecked.py | 2 +- daklib/dbconn.py | 17 ++++++++++++----- daklib/queue.py | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/dak/process_unchecked.py b/dak/process_unchecked.py index 0645dd9f..48c3839b 100755 --- a/dak/process_unchecked.py +++ b/dak/process_unchecked.py @@ -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() diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 56ff65aa..6d5497fc 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -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') ################################################################################ diff --git a/daklib/queue.py b/daklib/queue.py index 4e536877..cee15a5a 100755 --- a/daklib/queue.py +++ b/daklib/queue.py @@ -1734,7 +1734,7 @@ distribution.""" # 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) -- 2.39.5