X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fbinary.py;h=d83737547948da97c8632bd50ea36a861871ac35;hb=7de18480f8a0da2b977077e01bab9176c343676f;hp=70133db693e3f731f930187fe6039894f2b49b69;hpb=1483a68353fe374254379f4560cc245fbf2523d4;p=dak.git 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()