X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=daklib%2Fbinary.py;h=042cd266070a300f6e62644f8c709866cf6e7de1;hb=8c5aeba3e18751fd6a09d62e9c7bcf7bd56fd881;hp=70133db693e3f731f930187fe6039894f2b49b69;hpb=9f371390bb90395b2f2f0b65c91c21047896774a;p=dak.git diff --git a/daklib/binary.py b/daklib/binary.py index 70133db6..042cd266 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,9 +41,18 @@ 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): shutil.rmtree(self.tmpdir) + self.tmpdir = None def __scan_ar(self): # get a list of the ar contents @@ -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 ) @@ -104,7 +115,7 @@ class Binary(object): return not rejected - def scan_package(self): + def scan_package(self, bootstrap_id=0): """ Unpack the .deb, do sanity checking, and gather info from it. @@ -112,6 +123,11 @@ class Binary(object): the hopefully near future, it should also include gathering info from the control file. + @ptype bootstrap_id: int + @param bootstrap_id: the id of the binary these packages + should be associated or zero meaning we are not bootstrapping + so insert into a temporary table + @return True if the deb is valid and contents were imported """ rejected = not self.valid_deb() @@ -123,17 +139,18 @@ 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() if self.chunks[2] == "data.tar.gz": data = tarfile.open(os.path.join(self.tmpdir, "data.tar.gz"), "r:gz") elif self.chunks[2] == "data.tar.bz2": data = tarfile.open(os.path.join(self.tmpdir, "data.tar.bz2" ), "r:bz2") - return DBConn().insert_content_paths(pkg, [ tarinfo.name for tarinfo in data if tarinfo.isdir()]) + if bootstrap_id: + return DBConn().insert_content_paths(bootstrap_id, [ tarinfo.name for tarinfo in data if not tarinfo.isdir()]) + else: + pkg = deb822.Packages.iter_paragraphs( control.extractfile('./control') ).next() + return DBConn().insert_pending_content_paths(pkg, [ tarinfo.name for tarinfo in data if not tarinfo.isdir()]) except: traceback.print_exc() @@ -143,9 +160,6 @@ class Binary(object): finally: os.chdir( cwd ) - - - if __name__ == "__main__": Binary( "/srv/ftp.debian.org/queue/accepted/halevt_0.1.3-2_amd64.deb" ).scan_package()