]> git.decadent.org.uk Git - dak.git/commitdiff
Test and refactor get_component_by_package_suite().
authorTorsten Werner <twerner@debian.org>
Wed, 26 Jan 2011 23:07:48 +0000 (00:07 +0100)
committerTorsten Werner <twerner@debian.org>
Wed, 26 Jan 2011 23:07:48 +0000 (00:07 +0100)
Signed-off-by: Torsten Werner <twerner@debian.org>
dak/examine_package.py
daklib/dbconn.py
tests/dbtest_packages.py

index 0e1b34ff23ee9b86802af1668c7d574b868e34a1..0d98497ec1fc39797125e33241e33a8de58e4348 100755 (executable)
@@ -60,7 +60,7 @@ import commands
 import threading
 
 from daklib import utils
-from daklib.dbconn import DBConn, get_binary_from_name_suite
+from daklib.dbconn import DBConn, get_component_by_package_suite
 from daklib.regexes import html_escaping, re_html_escaping, re_version, re_spacestrip, \
                            re_contrib, re_nonfree, re_localhost, re_newlinespace, \
                            re_package, re_doc_directory
@@ -325,9 +325,9 @@ def read_changes_or_dsc (suite, filename, session = None):
 def create_depends_string (suite, depends_tree, session = None):
     result = ""
     if suite == 'experimental':
-        suite_where = "in ('experimental','unstable')"
+        suite_list = ['experimental','unstable']
     else:
-        suite_where = "= '%s'" % suite
+        suite_list = [suite]
 
     comma_count = 1
     for l in depends_tree:
@@ -339,17 +339,15 @@ def create_depends_string (suite, depends_tree, session = None):
                 result += " | "
             # doesn't do version lookup yet.
 
-            res = get_binary_from_name_suite(d['name'], suite_where, session)
-            if res.rowcount > 0:
-                i = res.fetchone()
-
+            component = get_component_by_package_suite(d['name'], suite_list, session)
+            if component is not None:
                 adepends = d['name']
                 if d['version'] != '' :
                     adepends += " (%s)" % (d['version'])
 
-                if i[2] == "contrib":
+                if component == "contrib":
                     result += colour_output(adepends, "contrib")
-                elif i[2] == "non-free":
+                elif component == "non-free":
                     result += colour_output(adepends, "nonfree")
                 else :
                     result += colour_output(adepends, "main")
index e1e21d2b2b1f10a386dd42c50460287d7e6c8f4d..97b76e0aff970ba2275e428c0e0ef22783e2166a 100755 (executable)
@@ -472,24 +472,16 @@ def get_suites_binary_in(package, session=None):
 __all__.append('get_suites_binary_in')
 
 @session_wrapper
-def get_binary_from_name_suite(package, suitename, session=None):
+def get_component_by_package_suite(package, suite_list, session=None):
     ### For dak examine-package
-    ### XXX: Doesn't use object API yet
-
-    sql = """SELECT DISTINCT(b.package), b.version, c.name, su.suite_name
-             FROM binaries b, files fi, location l, component c, bin_associations ba, suite su
-             WHERE b.package='%(package)s'
-               AND b.file = fi.id
-               AND fi.location = l.id
-               AND l.component = c.id
-               AND ba.bin=b.id
-               AND ba.suite = su.id
-               AND su.suite_name %(suitename)s
-          ORDER BY b.version DESC"""
-
-    return session.execute(sql % {'package': package, 'suitename': suitename})
-
-__all__.append('get_binary_from_name_suite')
+
+    return session.query(Component.component_name). \
+        join(Component.location, Location.files, PoolFile.binary). \
+        filter_by(package = package). \
+        join(DBBinary.suites).filter(Suite.suite_name.in_(suite_list)). \
+        limit(1).scalar()
+
+__all__.append('get_component_by_package_suite')
 
 @session_wrapper
 def get_binary_components(package, suitename, arch, session=None):
index 12ab5960ded9a9795604a6d84746d86f64f0b67d..7015c7fb562f57cd97a93828676459a36c4a72bf 100755 (executable)
@@ -6,7 +6,8 @@ from daklib.dbconn import Architecture, Suite, get_suite_architectures, \
     get_architecture_suites, Maintainer, DBSource, Location, PoolFile, \
     check_poolfile, get_poolfile_like_name, get_source_in_suite, \
     get_suites_source_in, add_dsc_to_db, source_exists, DBBinary, \
-    get_suites_binary_in, add_deb_to_db, Component
+    get_suites_binary_in, add_deb_to_db, Component, \
+    get_component_by_package_suite
 from daklib.queue_install import package_to_suite
 from daklib.queue import get_newest_source, get_suite_version_by_source, \
     get_source_by_package_and_suite, get_suite_version_by_package
@@ -523,5 +524,15 @@ class PackageTestCase(DBDakTestCase):
         self.assertEqual(self.loc['main'], self.comp['main'].location)
         self.assertEqual(self.loc['contrib'], self.comp['contrib'].location)
 
+    def test_get_component_by_package_suite(self):
+        'test get_component_by_package_suite()'
+
+        result = get_component_by_package_suite('hello', ['sid'], self.session)
+        self.assertEqual('main', result)
+        result = get_component_by_package_suite('hello', ['hamm'], self.session)
+        self.assertEqual(None, result)
+        result = get_component_by_package_suite('foobar', ['sid'], self.session)
+        self.assertEqual(None, result)
+
 if __name__ == '__main__':
     unittest.main()