]> git.decadent.org.uk Git - dak.git/blobdiff - daklib/dbconn.py
add get_split_maintainer method
[dak.git] / daklib / dbconn.py
index 42ef7e9f78eb5da11fd116ed88231fba25791fd5..113c38aa5fef3bf2d7a31015fa7622440ad73be4 100755 (executable)
@@ -44,6 +44,7 @@ from sqlalchemy.orm import sessionmaker, mapper, relation
 from sqlalchemy.exc import *
 
 from singleton import Singleton
+from textutils import fix_maintainer
 
 ################################################################################
 
@@ -210,6 +211,23 @@ def get_binaries_from_name(package, session=None):
 
 __all__.append('get_binaries_from_name')
 
+def get_binary_components(package, suitename, arch, session=None):
+# Check for packages that have moved from one component to another
+    query = """SELECT c.name FROM binaries b, bin_associations ba, suite s, location l, component c, architecture a, files f
+    WHERE b.package=:package AND s.suite_name=:suitename
+      AND (a.arch_string = :arch OR a.arch_string = 'all')
+      AND ba.bin = b.id AND ba.suite = s.id AND b.architecture = a.id
+      AND f.location = l.id
+      AND l.component = c.id
+      AND b.file = f.id"""
+
+    vals = {'package': package, 'suitename': suitename, 'arch': arch}
+
+    if session is None:
+        session = DBConn().session()
+    return session.execute(query, vals)
+
+__all__.append('get_binary_components')
 ################################################################################
 
 class Component(object):
@@ -532,6 +550,12 @@ class Maintainer(object):
     def __repr__(self):
         return '''<Maintainer '%s' (%s)>''' % (self.name, self.maintainer_id)
 
+    def get_split_maintainer(self):
+        if not hasattr(self, 'name') or self.name is None:
+            return ('', '', '', '')
+
+        return fix_maintainer(self.name.strip())
+
 __all__.append('Maintainer')
 
 ################################################################################
@@ -760,13 +784,17 @@ class DBSource(object):
 
 __all__.append('DBSource')
 
-def get_sources_from_name(source, session=None):
+def get_sources_from_name(source, dm_upload_allowed=None, session=None):
     """
     Returns list of DBSource objects for given C{source} name
 
     @type source: str
     @param source: DBSource package name to search for
 
+    @type dm_upload_allowed: bool
+    @param dm_upload_allowed: If None, no effect.  If True or False, only
+    return packages with that dm_upload_allowed setting
+
     @type session: Session
     @param session: Optional SQL session object (a temporary one will be
     generated if not supplied)
@@ -776,7 +804,12 @@ def get_sources_from_name(source, session=None):
     """
     if session is None:
         session = DBConn().session()
-    return session.query(DBSource).filter_by(source=source).all()
+
+    q = session.query(DBSource).filter_by(source=source)
+    if dm_upload_allowed is not None:
+        q = q.filter_by(dm_upload_allowed=dm_upload_allowed)
+
+    return q.all()
 
 __all__.append('get_sources_from_name')
 
@@ -908,13 +941,21 @@ class SuiteArchitecture(object):
 
 __all__.append('SuiteArchitecture')
 
-def get_suite_architectures(suite, session=None):
+def get_suite_architectures(suite, skipsrc=False, skipall=False, session=None):
     """
     Returns list of Architecture objects for given C{suite} name
 
     @type source: str
     @param source: Suite name to search for
 
+    @type skipsrc: boolean
+    @param skipsrc: Whether to skip returning the 'source' architecture entry
+    (Default False)
+
+    @type skipall: boolean
+    @param skipall: Whether to skip returning the 'all' architecture entry
+    (Default False)
+
     @type session: Session
     @param session: Optional SQL session object (a temporary one will be
     generated if not supplied)
@@ -928,7 +969,12 @@ def get_suite_architectures(suite, session=None):
 
     q = session.query(Architecture)
     q = q.join(SuiteArchitecture)
-    q = q.join(Suite).filter_by(suite_name=suite).order_by('arch_string')
+    q = q.join(Suite).filter_by(suite_name=suite)
+    if skipsrc:
+        q = q.filter(Architecture.arch_string != 'source')
+    if skipall:
+        q = q.filter(Architecture.arch_string != 'all')
+    q = q.order_by('arch_string')
     return q.all()
 
 __all__.append('get_suite_architectures')
@@ -944,6 +990,20 @@ class Uid(object):
 
 __all__.append('Uid')
 
+def get_uid_from_fingerprint(fpr, session=None):
+    if session is None:
+        session = DBConn().session()
+
+    q = session.query(Uid)
+    q = q.join(Fingerprint).filter_by(fingerprint=fpr)
+
+    if q.count() != 1:
+        return None
+    else:
+        return q.one()
+
+__all__.append('get_uid_from_fingerprint')
+
 ################################################################################
 
 class DBConn(Singleton):
@@ -1164,7 +1224,8 @@ class DBConn(Singleton):
                                  architecture = relation(Architecture)))
 
         mapper(Uid, self.tbl_uid,
-               properties = dict(uid_id = self.tbl_uid.c.id))
+               properties = dict(uid_id = self.tbl_uid.c.id,
+                                 fingerprint = relation(Fingerprint)))
 
     ## Connection functions
     def __createconn(self):