]> git.decadent.org.uk Git - dak.git/blobdiff - dak/contents.py
allow contents files to be written to an alternate location
[dak.git] / dak / contents.py
index 5ff121bc76684668f542646e02604ba27bfc2231..a2f99ae7e3ee0d2b57c197aa299b43436fc9766b 100644 (file)
@@ -191,14 +191,12 @@ class Contents(object):
                     h = open(os.path.join( Config()["Dir::Templates"],
                                            Config()["Contents::Header"] ), "r")
                     self.header = h.read()
-                    print( "header: %s" % self.header )
                     h.close()
                 except:
                     log.error( "error opening header file: %d\n%s" % (Config()["Contents::Header"],
                                                                       traceback.format_exc() ))
                     self.header = False
             else:
-                print( "no header" )
                 self.header = False
 
         return self.header
@@ -211,7 +209,11 @@ class Contents(object):
         Internal method for writing all the results to a given file.
         The cursor should have a result set generated from a query already.
         """
-        f = gzip.open(Config()["Dir::Root"] + filename, "w")
+        filepath = Config()["Contents::Root"] + filename
+        filedir = os.path.dirname(filepath)
+        if not os.path.isdir(filedir):
+            os.makedirs(filedir)
+        f = gzip.open(filepath, "w")
         try:
             header = self._getHeader()
 
@@ -224,7 +226,7 @@ class Contents(object):
                     return
 
                 num_tabs = max(1,
-                               int( math.ceil( (self._goal_column - len(contents[0])) / 8) ) )
+                               int(math.ceil((self._goal_column - len(contents[0])) / 8)))
                 f.write(contents[0] + ( '\t' * num_tabs ) + contents[-1] + "\n")
 
         finally:
@@ -263,18 +265,21 @@ class Contents(object):
             for arch_id in arch_list:
                 cursor.execute( "EXECUTE debs_q(%d, %d)" % ( suite_id, arch_id[0] ) )
 
-                debs = cursor.fetchall()
                 count = 0
-                for deb in debs:
+                while True:
+                    deb = cursor.fetchone()
+                    if not deb:
+                        break
                     count += 1
-                    cursor.execute( "EXECUTE olddeb_q(%d)" % (deb[0] ) )
-                    old = cursor.fetchone()
+                    cursor1 = DBConn().cursor();
+                    cursor1.execute( "EXECUTE olddeb_q(%d)" % (deb[0] ) )
+                    old = cursor1.fetchone()
                     if old:
                         log.debug( "already imported: %s" % deb[1] )
                     else:
                         debfile = os.path.join( pooldir, deb[1] )
                         if os.path.exists( debfile ):
-                            Binary(f).scan_package( deb[0] )
+                            Binary(debfile).scan_package( deb[0] )
                         else:
                             log.error( "missing .deb: %s" % deb[1] )