From b373c111451a76576c9bf30eefff27df959d66e0 Mon Sep 17 00:00:00 2001 From: Mike O'Connor Date: Sun, 22 Feb 2009 09:55:49 -0500 Subject: [PATCH] better cleanup of temporary files, consolidate some repeated code Signed-off-by: Mike O'Connor --- dak/contents.py | 13 ++++--------- dak/dakdb/update6.py | 2 +- dak/process_unchecked.py | 3 ++- daklib/binary.py | 15 ++++++++++++--- daklib/utils.py | 4 ++-- 5 files changed, 21 insertions(+), 16 deletions(-) diff --git a/dak/contents.py b/dak/contents.py index f423b197..eb9e5c38 100644 --- a/dak/contents.py +++ b/dak/contents.py @@ -308,18 +308,13 @@ class Contents(object): # The MORE fun part. Ok, udebs need their own contents files, udeb, and udeb-nf (not-free) # This is HORRIBLY debian specific :-/ - # First off, udeb - section_id = DBConn().get_section_id('debian-installer') # all udebs should be here) - if section_id != -1: - cursor.execute("EXECUTE udeb_contents_q(%d,%d,%d)" % (section_id, suite_id, suite_id)) - self._write_content_file(cursor, "dists/%s/Contents-udeb.gz" % suite) - - # Once more, with non-free - section_id = DBConn().get_section_id('non-free/debian-installer') # all udebs should be here) + for section_id, fn_pattern in [("debian-installer","dists/%s/Contents-udeb.gz"), + ("non-free/debian-installer", "dists/%s/Contents-udeb-nf.gz")] + section_id = DBConn().get_section_id(section_id) # all udebs should be here) if section_id != -1: cursor.execute("EXECUTE udeb_contents_q(%d,%d,%d)" % (section_id, suite_id, suite_id)) - self._write_content_file(cursor, "dists/%s/Contents-udeb-nf.gz" % suite) + self._write_content_file(cursor, fn_pattern % suite) ################################################################################ diff --git a/dak/dakdb/update6.py b/dak/dakdb/update6.py index 514a4e87..d1781223 100644 --- a/dak/dakdb/update6.py +++ b/dak/dakdb/update6.py @@ -82,7 +82,7 @@ def do_update(self): c.execute( "CREATE INDEX content_assocaitions_binary ON content_associations(binary_pkg)" ) - c.execute("UPDATE config SET value = '2' WHERE name = 'db_revision'") + c.execute("UPDATE config SET value = '6' WHERE name = 'db_revision'") self.db.commit() print "REMINDER: Remember to fully regenerate the Contents files before running import-contents" diff --git a/dak/process_unchecked.py b/dak/process_unchecked.py index 26b2ae55..aa2926a0 100755 --- a/dak/process_unchecked.py +++ b/dak/process_unchecked.py @@ -40,7 +40,8 @@ import time import tempfile import traceback import tarfile -import apt_inst, apt_pkg +import apt_inst +import apt_pkg from debian_bundle import deb822 from daklib.dbconn import DBConn from daklib.binary import Binary diff --git a/daklib/binary.py b/daklib/binary.py index 70133db6..d8373754 100755 --- a/daklib/binary.py +++ b/daklib/binary.py @@ -30,6 +30,7 @@ import tempfile import tarfile import commands import traceback +import atexit from debian_bundle import deb822 from dbconn import DBConn @@ -40,8 +41,17 @@ class Binary(object): self.chunks = None def __del__(self): - # we need to remove the temporary directory, if we created one + """ + make sure we cleanup when we are garbage collected. + """ + self.cleanup() + + def _cleanup(self): + """ + we need to remove the temporary directory, if we created one + """ if self.tmpdir and os.path.exists(self.tmpdir): + self.tmpdir = None shutil.rmtree(self.tmpdir) def __scan_ar(self): @@ -75,6 +85,7 @@ class Binary(object): reject(utils.prefix_multi_line_string(output, " [ar output:] "), "") else: self.tmpdir = tmpdir + atexit.register( self.cleanup ) finally: os.chdir( cwd ) @@ -123,8 +134,6 @@ class Binary(object): os.chdir(self.tmpdir) if self.chunks[1] == "control.tar.gz": control = tarfile.open(os.path.join(self.tmpdir, "control.tar.gz" ), "r:gz") - elif self.chunks[1] == "control.tar.bz2": - control = tarfile.open(os.path.join(self.tmpdir, "control.tar.bz2" ), "r:bz2") pkg = deb822.Packages.iter_paragraphs( control.extractfile('./control') ).next() diff --git a/daklib/utils.py b/daklib/utils.py index a45eceea..27c3af38 100755 --- a/daklib/utils.py +++ b/daklib/utils.py @@ -1532,8 +1532,8 @@ def generate_contents_information(filename): """ Generate a list of flies contained in a .deb - @type filename: string - @param filename: the path to a data.tar.gz or data.tar.bz2 + @ptype filename: string + @param filename: the path to a .deb @rtype: list @return: a list of files in the data.tar.* portion of the .deb -- 2.39.2