r393 - /debtorrent/trunk/uniquely_projectb.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Wed Jun 25 20:39:07 UTC 2008


Author: camrdale-guest
Date: Wed Jun 25 20:39:07 2008
New Revision: 393

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=393
Log:
Update uniquely_projectb to remove duplication for arch:all packages

Modified:
    debtorrent/trunk/uniquely_projectb.py

Modified: debtorrent/trunk/uniquely_projectb.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/uniquely_projectb.py?rev=393&op=diff
==============================================================================
--- debtorrent/trunk/uniquely_projectb.py (original)
+++ debtorrent/trunk/uniquely_projectb.py Wed Jun 25 20:39:07 2008
@@ -304,6 +304,79 @@
     f.close()
     rename(filename + '.new', filename)
 
+def process_file(db, torrent_file, release_headers, packages, suite, codename, component, arch):
+    """
+    
+    @type db: C{DB-APIv2 connection}
+    @param db: an open connection to the projectb database
+    @type torrent_file: C{string}
+    @param torrent_file: the unique pieces file to process
+    @type release_headers: C{dictionary}
+    @param release_headers: the headers from the Release file
+    @type packages: C{list} of C{string}
+    @param packages: the list of Packages files listed in the Release file
+    @type suite: C{string}
+    @param suite: the suite name (e.g. testing, unstable)
+    @type codename: C{string}
+    @param codename: the codename of the suite (e.g. sid, lenny)
+    @type component: C{string}
+    @param component: the component name (e.g. main, contrib, non-free)
+    @type arch: C{string}
+    @param arch: the architecture name (e.g. i386, amd64, all)
+    
+    """
+    
+    # Find the Packages file that will be parsed
+    if arch != 'all':
+        found = False
+        for filename in packages:
+            if (filename.find(component) >= 0 and 
+                filename.find("binary-"+arch) >= 0):
+                found = True
+                break
+        if not found:
+            print "WARNING: no matching Packages file for component %s, arch %s" % (component, arch)
+            if exists(torrent_file):
+                remove(torrent_file)
+            return
+        packages.pop(packages.index(filename))
+
+    # Get the old data for this torrent, if any existed
+    print torrent_file + ": reading ...",
+    sys.stdout.flush()
+    old_pieces, headers = get_old(torrent_file)
+
+    # Update the headers from the Release file ones
+    if update_headers(headers, release_headers, component, arch):
+        print "new torrent created ...",
+        sys.stdout.flush()
+        old_pieces = {}
+
+    # Parse the database for the new data
+    print "updating ...",
+    sys.stdout.flush()
+    pieces, new_pieces = get_new(db, suite, codename, component, arch,
+                                    old_pieces)
+
+    # Add the old removed pieces so out-of-date mirrors will work too
+    for file in old_pieces:
+        pieces[old_pieces[file]] = file
+
+    if pieces or new_pieces:
+        # Add any new pieces to the end of pieces
+        add_new(pieces, new_pieces, headers)
+        
+        # Write the headers
+        print "writing ...",
+        sys.stdout.flush()
+        write_file(torrent_file, pieces, headers)
+    else:
+        print "empty ...",
+        if exists(torrent_file):
+            remove(torrent_file)
+        
+    print "done."
+
 def run(db, releasefile):
     """Process a single Release file.
     
@@ -318,103 +391,21 @@
     print "Processing: %s" % releasefile
     release_headers, packages = read_release(releasefile)
     
+    # Extract the relevant headers
     suite = release_headers['Suite']
     codename = release_headers["Codename"]
+    components = release_headers["Components"].split()
+    archs = release_headers["Architectures"].split()
+    archs.append('all')
+    archs.sort()
     torrent_prefix = "dists_" + codename + "_"
     torrent_suffix = "_Packages-torrent.gz"
     
-    for component in release_headers["Components"].split():
-        # Get the old 'all' data
-        all_file = torrent_prefix + component + "_binary-all" + torrent_suffix
-        print all_file + ": reading ...",
-        sys.stdout.flush()
-        old_all_pieces, all_headers = get_old(all_file)
-    
-        # First update the 'all' headers
-        if update_headers(all_headers, release_headers, component, "all"):
-            # If it has, then reset the torrent
-            print "new torrent created ...",
-            sys.stdout.flush()
-            old_all_pieces = {}
-    
-        # Parse the database for the new data
-        print "updating ...",
-        sys.stdout.flush()
-        all_pieces, all_new_pieces = get_new(db, suite, codename, component, 'all',
-                                             old_all_pieces)
-
-        # Add the old removed pieces so out-of-date mirrors will work too
-        for file in old_all_pieces:
-            all_pieces[old_all_pieces[file]] = file
-
-        # If there were 'all' files found
-        if all_pieces or all_new_pieces:
-            # Process the new 'all' files found
-            add_new(all_pieces, all_new_pieces, all_headers)
-        
-            # Write the all_headers
-            print "writing ...",
-            sys.stdout.flush()
-            write_file(all_file, all_pieces, all_headers)
-        else:
-            print "empty ...",
-            if exists(all_file):
-                remove(all_file)
-    
-        print "done."
-    
-        for arch in release_headers["Architectures"].split():
+    # Process each components' architecture
+    for component in components:
+        for arch in archs:
             torrent_file = torrent_prefix + component + "_binary-" + arch + torrent_suffix
-    
-            # Find the Packages file that will be parsed
-            found = False
-            for filename in packages:
-                if (filename.find(component) >= 0 and 
-                    filename.find("binary-"+arch) >= 0):
-                    found = True
-                    break
-            if not found:
-                print "WARNING: no matching Packages file for component %s, arch %s" % (component, arch)
-                if exists(torrent_file):
-                    remove(torrent_file)
-                continue
-            packages.pop(packages.index(filename))
-    
-            # Get the old data for this torrent, if any existed
-            print torrent_file + ": reading ...",
-            sys.stdout.flush()
-            old_pieces, headers = get_old(torrent_file)
-    
-            # Update the headers from the Release file ones
-            if update_headers(headers, release_headers, component, arch):
-                print "new torrent created ...",
-                sys.stdout.flush()
-                old_pieces = {}
-    
-            # Parse the database for the new data
-            print "updating ...",
-            sys.stdout.flush()
-            pieces, new_pieces = get_new(db, suite, codename, component, arch,
-                                         old_pieces)
-
-            # Add the old removed pieces so out-of-date mirrors will work too
-            for file in old_pieces:
-                pieces[old_pieces[file]] = file
-    
-            if pieces or new_pieces:
-                # Add any new pieces to the end of pieces
-                add_new(pieces, new_pieces, headers)
-                
-                # Write the headers
-                print "writing ...",
-                sys.stdout.flush()
-                write_file(torrent_file, pieces, headers)
-            else:
-                print "empty ...",
-                if exists(torrent_file):
-                    remove(torrent_file)
-                
-            print "done."
+            process_file(db, torrent_file, release_headers, packages, suite, codename, component, arch)
     
     if packages:
         print "The following packages files were not used:"




More information about the Debtorrent-commits mailing list