X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fdbconn.py;h=5a7dc52dc1b183b7d32a60ef0004b94616f5e2b7;hb=3aaef9d2b20417a631d59a990dfdfb188cf3f102;hp=3a11c2a1de531c11230f2638ddf3bee02d23e94e;hpb=6c67b339caabb38fa6eea015dad09d68d2dc370d;p=dak.git diff --git a/daklib/dbconn.py b/daklib/dbconn.py index 3a11c2a1..5a7dc52d 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -40,6 +40,9 @@ import traceback from sqlalchemy import create_engine, Table, MetaData, select from sqlalchemy.orm import sessionmaker, mapper, relation +# Don't remove this, we re-export the exceptions to scripts which import us +from sqlalchemy.exc import * + from singleton import Singleton ################################################################################ @@ -73,6 +76,29 @@ def get_architecture(architecture, session=None): return None return q.one() +def get_architecture_suites(architecture, session=None): + """ + Returns list of Suite objects for given C{architecture} name + + @type source: str + @param source: Architecture 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: list of Suite objects for the given name (may be empty) + """ + + if session is None: + session = DBConn().session() + + q = session.query(Suite) + q = q.join(SuiteArchitecture) + q = q.join(Architecture).filter_by(arch_string=architecture).order_by('suite_name') + return q.all() + class Archive(object): def __init__(self, *args, **kwargs): pass @@ -139,6 +165,24 @@ def get_binary_from_id(id, session=None): return None return q.one() +def get_binaries_from_name(package, session=None): + """ + Returns list of Binary objects for given C{package} name + + @type package: str + @param package: Binary package 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: list of Binary objects for the given name (may be empty) + """ + if session is None: + session = DBConn().session() + return session.query(Binary).filter_by(package=package).all() + class Component(object): def __init__(self, *args, **kwargs): pass @@ -357,6 +401,24 @@ class Source(object): def __repr__(self): return '' % (self.source, self.version) +def get_sources_from_name(source, session=None): + """ + Returns list of Source objects for given C{source} name + + @type source: str + @param source: Source package 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: list of Source objects for the given name (may be empty) + """ + if session is None: + session = DBConn().session() + return session.query(Source).filter_by(source=source).all() + def get_source_in_suite(source, suite, session=None): """ Returns list of Source objects for a combination of C{source} and C{suite}. @@ -405,6 +467,36 @@ class Suite(object): def __repr__(self): return '' % self.suite_name +def get_suite_architecture(suite, architecture, session=None): + """ + Returns a SuiteArchitecture object given C{suite} and ${arch} or None if it + doesn't exist + + @type suite: str + @param suite: Suite name to search for + + @type architecture: str + @param architecture: Architecture name to search for + + @type session: Session + @param session: Optional SQL session object (a temporary one will be + generated if not supplied) + + @rtype: SuiteArchitecture + @return: the SuiteArchitecture object or None + """ + + if session is None: + session = DBConn().session() + + q = session.query(SuiteArchitecture) + q = q.join(Architecture).filter_by(arch_string=architecture) + q = q.join(Suite).filter_by(suite_name=suite) + if q.count() == 0: + return None + return q.one() + + def get_suite(suite, session=None): """ Returns Suite object for given C{suite name}. @@ -434,6 +526,30 @@ class SuiteArchitecture(object): def __repr__(self): return '' % (self.suite_id, self.arch_id) +def get_suite_architectures(suite, session=None): + """ + Returns list of Architecture objects for given C{suite} name + + @type source: str + @param source: 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: list of Architecture objects for the given name (may be empty) + """ + + if session is None: + session = DBConn().session() + + q = session.query(Architecture) + q = q.join(SuiteArchitecture) + q = q.join(Suite).filter_by(suite_name=suite).order_by('arch_string') + return q.all() + + class Uid(object): def __init__(self, *args, **kwargs): pass @@ -684,7 +800,7 @@ class DBConn(Singleton): self.db_meta.bind = self.db_pg self.db_smaker = sessionmaker(bind=self.db_pg, autoflush=True, - transactional=True) + autocommit=True) self.__setuptables() self.__setupmappers() @@ -856,31 +972,6 @@ def get_or_set_contents_path_id(self, path): traceback.print_exc() raise -def get_suite_architectures(self, suite): - """ - Returns list of architectures for C{suite}. - - @type suite: string, int - @param suite: the suite name or the suite_id - - @rtype: list - @return: the list of architectures for I{suite} - """ - - suite_id = None - if type(suite) == str: - suite_id = self.get_suite_id(suite) - elif type(suite) == int: - suite_id = suite - else: - return None - - c = self.db_con.cursor() - c.execute( """SELECT a.arch_string FROM suite_architectures sa - JOIN architecture a ON (a.id = sa.architecture) - WHERE suite='%s'""" % suite_id ) - - return map(lambda x: x[0], c.fetchall()) def insert_content_paths(self, bin_id, fullpaths): """