]> git.decadent.org.uk Git - dak.git/blobdiff - daklib/binary.py
get rid of finally:
[dak.git] / daklib / binary.py
index f9cf2437fe55f09ffed0218bf735628b07a2c764..a2601a7205799afd91cc4a79b7e2bdab20d0453c 100755 (executable)
@@ -115,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.
 
@@ -123,11 +123,18 @@ 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()
         self.__unpack()
 
+        result = False
+
         if not rejected and self.tmpdir:
             cwd = os.getcwd()
             try:
@@ -135,25 +142,24 @@ class Binary(object):
                 if self.chunks[1] == "control.tar.gz":
                     control = tarfile.open(os.path.join(self.tmpdir, "control.tar.gz" ), "r:gz")
 
-                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 not tarinfo.isdir()])
+                if bootstrap_id:
+                    result = 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()
+                    result = DBConn().insert_pending_content_paths(pkg, [ tarinfo.name for tarinfo in data if not tarinfo.isdir()])
 
             except:
                 traceback.print_exc()
+                result = False
 
-                return False
-
-            finally:
-                os.chdir( cwd )
-
-
-
+        os.chdir( cwd )
+        return result
 
 if __name__ == "__main__":
     Binary( "/srv/ftp.debian.org/queue/accepted/halevt_0.1.3-2_amd64.deb" ).scan_package()