From: Torsten Werner Date: Wed, 7 Jul 2010 21:38:51 +0000 (+0000) Subject: show-new: reduce number of open DB sessions X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d34d27f3196d602d8957463b4495cefbf402dc66;p=dak show-new: reduce number of open DB sessions Signed-off-by: Torsten Werner --- diff --git a/dak/examine_package.py b/dak/examine_package.py index 617fc7ad..5a35a99d 100755 --- a/dak/examine_package.py +++ b/dak/examine_package.py @@ -275,7 +275,7 @@ def read_control (filename): return (control, control_keys, section, depends, recommends, arch, maintainer) -def read_changes_or_dsc (suite, filename): +def read_changes_or_dsc (suite, filename, session = None): dsc = {} dsc_file = utils.open_file(filename) @@ -294,7 +294,7 @@ def read_changes_or_dsc (suite, filename): for k in dsc.keys(): if k in ("build-depends","build-depends-indep"): - dsc[k] = create_depends_string(suite, split_depends(dsc[k])) + dsc[k] = create_depends_string(suite, split_depends(dsc[k]), session) elif k == "architecture": if (dsc["architecture"] != "any"): dsc['architecture'] = colour_output(dsc["architecture"], 'arch') @@ -311,7 +311,7 @@ def read_changes_or_dsc (suite, filename): filecontents = '\n'.join(map(lambda x: format_field(x,dsc[x.lower()]), keysinorder))+'\n' return filecontents -def create_depends_string (suite, depends_tree): +def create_depends_string (suite, depends_tree, session = None): result = "" if suite == 'experimental': suite_where = "in ('experimental','unstable')" @@ -328,7 +328,7 @@ def create_depends_string (suite, depends_tree): result += " | " # doesn't do version lookup yet. - res = get_binary_from_name_suite(d['name'], suite_where) + res = get_binary_from_name_suite(d['name'], suite_where, session) if res.rowcount > 0: i = res.fetchone() @@ -369,7 +369,7 @@ def output_package_relations (): package_relations.clear() return foldable_output("Package relations", "relations", to_print) -def output_deb_info(suite, filename, packagename): +def output_deb_info(suite, filename, packagename, session = None): (control, control_keys, section, depends, recommends, arch, maintainer) = read_control(filename) if control == '': @@ -379,10 +379,10 @@ def output_deb_info(suite, filename, packagename): package_relations[packagename] = {} for key in control_keys : if key == 'Depends': - field_value = create_depends_string(suite, depends) + field_value = create_depends_string(suite, depends, session) package_relations[packagename][key] = field_value elif key == 'Recommends': - field_value = create_depends_string(suite, recommends) + field_value = create_depends_string(suite, recommends, session) package_relations[packagename][key] = field_value elif key == 'Section': field_value = section @@ -471,8 +471,8 @@ def get_readme_source (dsc_filename): return res -def check_dsc (suite, dsc_filename): - (dsc) = read_changes_or_dsc(suite, dsc_filename) +def check_dsc (suite, dsc_filename, session = None): + (dsc) = read_changes_or_dsc(suite, dsc_filename, session) return foldable_output(dsc_filename, "dsc", dsc, norow=True) + \ "\n" + \ foldable_output("lintian check for %s" % dsc_filename, @@ -481,7 +481,7 @@ def check_dsc (suite, dsc_filename): foldable_output("README.source for %s" % dsc_filename, "source-readmesource", get_readme_source(dsc_filename)) -def check_deb (suite, deb_filename): +def check_deb (suite, deb_filename, session = None): filename = os.path.basename(deb_filename) packagename = filename.split('_')[0] @@ -491,7 +491,7 @@ def check_deb (suite, deb_filename): is_a_udeb = 0 result = foldable_output("control file for %s" % (filename), "binary-%s-control"%packagename, - output_deb_info(suite, deb_filename, packagename), norow=True) + "\n" + output_deb_info(suite, deb_filename, packagename, session), norow=True) + "\n" if is_a_udeb: result += foldable_output("skipping lintian check for udeb", diff --git a/dak/show_new.py b/dak/show_new.py index 3c0b0467..cb40a4c9 100755 --- a/dak/show_new.py +++ b/dak/show_new.py @@ -170,7 +170,6 @@ def do_pkg(changes_file): else: u.source_file_checks(deb_filename, session) u.check_source_against_db(deb_filename, session) - session.close() u.pkg.changes["suite"] = u.pkg.changes["distribution"] new = determine_new(u.pkg.changes, files, 0) @@ -188,18 +187,19 @@ def do_pkg(changes_file): print >> outfile, html_header(changes["source"], filestoexamine) - check_valid(new) + check_valid(new, session) distribution = changes["distribution"].keys()[0] print >> outfile, examine_package.display_changes(distribution, changes_file) for fn in filter(lambda fn: fn.endswith(".dsc"), filestoexamine): - print >> outfile, examine_package.check_dsc(distribution, fn) + print >> outfile, examine_package.check_dsc(distribution, fn, session) for fn in filter(lambda fn: fn.endswith(".deb") or fn.endswith(".udeb"), filestoexamine): - print >> outfile, examine_package.check_deb(distribution, fn) + print >> outfile, examine_package.check_deb(distribution, fn, session) print >> outfile, html_footer() outfile.close() + session.close() ################################################################################ diff --git a/daklib/queue.py b/daklib/queue.py index 3ab87246..ca3c133e 100755 --- a/daklib/queue.py +++ b/daklib/queue.py @@ -187,7 +187,7 @@ def determine_new(changes, files, warn=1): ################################################################################ -def check_valid(new): +def check_valid(new, session = None): """ Check if section and priority for NEW packages exist in database. Additionally does sanity checks: @@ -204,13 +204,13 @@ def check_valid(new): priority_name = new[pkg]["priority"] file_type = new[pkg]["type"] - section = get_section(section_name) + section = get_section(section_name, session) if section is None: new[pkg]["section id"] = -1 else: new[pkg]["section id"] = section.section_id - priority = get_priority(priority_name) + priority = get_priority(priority_name, session) if priority is None: new[pkg]["priority id"] = -1 else: @@ -569,8 +569,8 @@ class Upload(object): architecture = control.Find("Architecture") upload_suite = self.pkg.changes["distribution"].keys()[0] - if architecture not in [a.arch_string for a in get_suite_architectures(default_suite, session)] \ - and architecture not in [a.arch_string for a in get_suite_architectures(upload_suite, session)]: + if architecture not in [a.arch_string for a in get_suite_architectures(default_suite, session = session)] \ + and architecture not in [a.arch_string for a in get_suite_architectures(upload_suite, session = session)]: self.rejects.append("Unknown architecture '%s'." % (architecture)) # Ensure the architecture of the .deb is one of the ones