From: Mark Hymers Date: Sun, 9 Aug 2009 13:46:18 +0000 (+0100) Subject: add get_sections and get_priorities X-Git-Url: https://git.decadent.org.uk/gitweb/?a=commitdiff_plain;h=935bd2ad8079341123590d80658562d81ac87c86;p=dak.git add get_sections and get_priorities Signed-off-by: Mark Hymers --- diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 43c0b698..22fa262c 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -1233,6 +1233,29 @@ def get_priority(priority, session=None): __all__.append('get_priority') +def get_priorities(session=None): + """ + Returns dictionary of priority names -> id mappings + + @type session: Session + @param session: Optional SQL session object (a temporary one will be + generated if not supplied) + + @rtype: dictionary + @return: dictionary of priority names -> id mappings + """ + if session is None: + session = DBConn().session() + + ret = {} + q = session.query(Priority) + for x in q.all(): + ret[x.priority] = x.priority_id + + return ret + +__all__.append('get_priorities') + ################################################################################ class Queue(object): @@ -1469,6 +1492,29 @@ def get_section(section, session=None): __all__.append('get_section') +def get_sections(session=None): + """ + Returns dictionary of section names -> id mappings + + @type session: Session + @param session: Optional SQL session object (a temporary one will be + generated if not supplied) + + @rtype: dictionary + @return: dictionary of section names -> id mappings + """ + if session is None: + session = DBConn().session() + + ret = {} + q = session.query(Section) + for x in q.all(): + ret[x.section] = x.section_id + + return ret + +__all__.append('get_sections') + ################################################################################ class DBSource(object):