X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fdbconn.py;h=ff00135f0998f339919feefb778a6e05030acf47;hb=5b63423b4fc6bb7a2a0c7ed5cf347eb8589440db;hp=b63b4a9380d1fed873d0031e25dd1286e08055cc;hpb=5a88b5a5f6632024f2f3735908972090470252e7;p=dak.git diff --git a/daklib/dbconn.py b/daklib/dbconn.py index b63b4a93..ff00135f 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -981,6 +981,42 @@ class Keyring(object): __all__.append('Keyring') +def get_or_set_keyring(keyring, session=None): + """ + If C{keyring} does not have an entry in the C{keyrings} table yet, create one + and return the new Keyring + If C{keyring} already has an entry, simply return the existing Keyring + + @type keyring: string + @param keyring: the keyring name + + @rtype: Keyring + @return: the Keyring object for this keyring + + """ + privatetrans = False + if session is None: + session = DBConn().session() + privatetrans = True + + try: + obj = session.query(Keyring).filter_by(keyring_name=keyring).first() + + if obj is None: + obj = Keyring(keyring_name=keyring) + session.add(obj) + if privatetrans: + session.commit() + else: + session.flush() + + return obj + finally: + if privatetrans: + session.close() + +__all__.append('get_or_set_keyring') + ################################################################################ class Location(object): @@ -1095,15 +1131,16 @@ def get_or_set_maintainer(name, session=None): __all__.append('get_or_set_maintainer') -def get_maintainer(maintainer_id, session=True): +def get_maintainer(maintainer_id, session=None): """ - Return the name of the maintainer behind C{maintainer_id}. + Return the name of the maintainer behind C{maintainer_id} or None if that + maintainer_id is invalid. @type maintainer_id: int @param maintainer_id: the id of the maintainer - @rtype: string - @return: the name of the maintainer + @rtype: Maintainer + @return: the Maintainer with this C{maintainer_id} """ privatetrans = False @@ -1112,7 +1149,7 @@ def get_maintainer(maintainer_id, session=True): privatetrans = True try: - return session.query(Maintainer).get(maintainer_id).name + return session.query(Maintainer).get(maintainer_id) finally: if privatetrans: session.close() @@ -1992,6 +2029,17 @@ __all__.append('SrcAssociation') ################################################################################ +class SrcFormat(object): + def __init__(self, *args, **kwargs): + pass + + def __repr__(self): + return '' % (self.format_name) + +__all__.append('SrcFormat') + +################################################################################ + class SrcUploader(object): def __init__(self, *args, **kwargs): pass @@ -2189,6 +2237,51 @@ __all__.append('get_suite_architectures') ################################################################################ +class SuiteSrcFormat(object): + def __init__(self, *args, **kwargs): + pass + + def __repr__(self): + return '' % (self.suite_id, self.src_format_id) + +__all__.append('SuiteSrcFormat') + +def get_suite_src_formats(suite, session=None): + """ + Returns list of allowed SrcFormat for C{suite}. + + @type suite: str + @param suite: Suite name to search for + + @type session: Session + @param session: Optional SQL session object (a temporary one will be + generated if not supplied) + + @rtype: list + @return: the list of allowed source formats for I{suite} + """ + + privatetrans = False + if session is None: + session = DBConn().session() + privatetrans = True + + q = session.query(SrcFormat) + q = q.join(SuiteSrcFormat) + q = q.join(Suite).filter_by(suite_name=suite) + q = q.order_by('format_name') + + ret = q.all() + + if privatetrans: + session.close() + + return ret + +__all__.append('get_suite_src_formats') + +################################################################################ + class Uid(object): def __init__(self, *args, **kwargs): pass @@ -2346,9 +2439,11 @@ class DBConn(Singleton): self.tbl_section = Table('section', self.db_meta, autoload=True) self.tbl_source = Table('source', self.db_meta, autoload=True) self.tbl_src_associations = Table('src_associations', self.db_meta, autoload=True) + self.tbl_src_format = Table('src_format', self.db_meta, autoload=True) self.tbl_src_uploaders = Table('src_uploaders', self.db_meta, autoload=True) self.tbl_suite = Table('suite', self.db_meta, autoload=True) self.tbl_suite_architectures = Table('suite_architectures', self.db_meta, autoload=True) + self.tbl_suite_src_formats = Table('suite_src_formats', self.db_meta, autoload=True) self.tbl_uid = Table('uid', self.db_meta, autoload=True) def __setupmappers(self): @@ -2510,6 +2605,10 @@ class DBConn(Singleton): source_id = self.tbl_src_associations.c.source, source = relation(DBSource))) + mapper(SrcFormat, self.tbl_src_format, + properties = dict(src_format_id = self.tbl_src_format.c.id, + format_name = self.tbl_src_format.c.format_name)) + mapper(SrcUploader, self.tbl_src_uploaders, properties = dict(uploader_id = self.tbl_src_uploaders.c.id, source_id = self.tbl_src_uploaders.c.source, @@ -2528,6 +2627,12 @@ class DBConn(Singleton): arch_id = self.tbl_suite_architectures.c.architecture, architecture = relation(Architecture))) + mapper(SuiteSrcFormat, self.tbl_suite_src_formats, + properties = dict(suite_id = self.tbl_suite_src_formats.c.suite, + suite = relation(Suite, backref='suitesrcformats'), + src_format_id = self.tbl_suite_src_formats.c.src_format, + src_format = relation(SrcFormat))) + mapper(Uid, self.tbl_uid, properties = dict(uid_id = self.tbl_uid.c.id, fingerprint = relation(Fingerprint)))