From: Mark Hymers Date: Mon, 25 May 2009 18:02:47 +0000 (+0100) Subject: move examine-package to sqla X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1aebafb6883d00176530d80ccd47fd348dfd3034;p=dak move examine-package to sqla Signed-off-by: Mark Hymers --- diff --git a/dak/examine_package.py b/dak/examine_package.py index fd06f519..42a4be77 100755 --- a/dak/examine_package.py +++ b/dak/examine_package.py @@ -48,8 +48,9 @@ import apt_pkg import apt_inst import shutil import commands -from daklib import database + from daklib import utils +from daklib.dbconn import DBConn, get_binary_from_name_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 @@ -57,11 +58,7 @@ from daklib.regexes import html_escaping, re_html_escaping, re_version, re_space ################################################################################ Cnf = None -projectB = None - Cnf = utils.get_conf() -projectB = pg.connect(Cnf["DB::Name"], Cnf["DB::Host"], int(Cnf["DB::Port"])) -database.init(Cnf, projectB) printed_copyrights = {} package_relations = {} #: Store relations of packages for later output @@ -315,6 +312,7 @@ def create_depends_string (suite, depends_tree): suite_where = " ='%s'" % suite comma_count = 1 + session = DBConn().session() for l in depends_tree: if (comma_count >= 2): result += ", " @@ -324,10 +322,9 @@ def create_depends_string (suite, depends_tree): result += " | " # doesn't do version lookup yet. - q = projectB.query("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='%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 %s ORDER BY b.version desc" % (d['name'], suite_where)) - ql = q.getresult() - if ql: - i = ql[0] + res = get_binary_from_name_suite(d['name'], suite_where) + if res.rowcount > 0: + i = res.fetchone() adepends = d['name'] if d['version'] != '' : @@ -551,7 +548,7 @@ def check_changes (changes_filename): # else: => byhand def main (): - global Cnf, projectB, db_files, waste, excluded + global Cnf, db_files, waste, excluded # Cnf = utils.get_conf() diff --git a/daklib/dbconn.py b/daklib/dbconn.py index c091aa94..9e09bdb3 100755 --- a/daklib/dbconn.py +++ b/daklib/dbconn.py @@ -211,6 +211,27 @@ def get_binaries_from_name(package, session=None): __all__.append('get_binaries_from_name') +def get_binary_from_name_suite(package, suitename, session=None): + ### For dak examine-package + ### XXX: Doesn't use object API yet + if session is None: + session = DBConn().session() + + 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 + 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 + ORDER BY b.version DESC""" + + return session.execute(sql, {'package': package, 'suitename': suitename}) + +__all__.append('get_binary_from_name_suite') + 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