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
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:
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")
__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):
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
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()