]> err.no Git - dak/commitdiff
show-new: reduce number of open DB sessions
authorTorsten Werner <twerner@debian.org>
Wed, 7 Jul 2010 21:38:51 +0000 (21:38 +0000)
committerTorsten Werner <twerner@debian.org>
Wed, 7 Jul 2010 21:38:51 +0000 (21:38 +0000)
Signed-off-by: Torsten Werner <twerner@debian.org>
dak/examine_package.py
dak/show_new.py
daklib/queue.py

index 617fc7ad77f6ed04f2bf437ab828e76eca87927d..5a35a99da9f7a28836fa955debec1b8bad37f60e 100755 (executable)
@@ -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",
index 3c0b046738017f003b7f264d3d493a612b28d764..cb40a4c98804be917ed9477039f9b65192bc1058 100755 (executable)
@@ -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()
 
 ################################################################################
 
index 3ab87246d1601f1fc5dd52912293deb155f95b38..ca3c133e1fd23e3b62bc00fca013124e2c973064 100755 (executable)
@@ -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