r398 - /debtorrent/trunk/uniquely.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Tue Jul 1 06:49:24 UTC 2008


Author: camrdale-guest
Date: Tue Jul  1 06:49:24 2008
New Revision: 398

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=398
Log:
Make some of the same changes to the non-projectb uniquely script.

Modified:
    debtorrent/trunk/uniquely.py

Modified: debtorrent/trunk/uniquely.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/uniquely.py?rev=398&op=diff
==============================================================================
--- debtorrent/trunk/uniquely.py (original)
+++ debtorrent/trunk/uniquely.py Tue Jul  1 06:49:24 2008
@@ -7,7 +7,7 @@
 import gzip
 from bz2 import BZ2File
 from math import ceil
-from os import remove, rename, system
+from os import remove, rename, system, symlink
 from os.path import exists
 from time import strftime, gmtime
 from debian_bundle import deb822
@@ -208,12 +208,12 @@
     
     # Open the possibly compressed file
     if filename.endswith(".gz"):
-        ret = system("zcat '%s' | grep -E '^(Filename:.*|Size:.*|Architecture:.*|)$' > '%s'" % (filename, tmpfile))
+        ret = system("zcat '%s' | awk '/^Filename:/ || /^Size:/ || /^Architecture:/ || /^$/ { print }' > '%s'" % (filename, tmpfile))
         if ret != 0:
             raise RuntimeError, 'Failed to decompress %s' % filename
         filename = tmpfile
     elif filename.endswith(".bz2"):
-        ret = system("bzcat '%s' | grep -E '^(Filename:.*|Size:.*|Architecture:.*|)$' > '%s'" % (filename, tmpfile))
+        ret = system("bzcat '%s' | awk '/^Filename:/ || /^Size:/ || /^Architecture:/ || /^$/ { print }' > '%s'" % (filename, tmpfile))
         if ret != 0:
             raise RuntimeError, 'Failed to decompress %s' % filename
         filename = tmpfile
@@ -334,13 +334,19 @@
     # Process the Release file
     print "Processing: %s" % releasefile
     release_headers, packages = read_release(releasefile)
-    
-    torrent_prefix = "dists_" + release_headers.get("Codename", "") + "_"
+
+    codename = release_headers["Codename"]
+    suite = release_headers["Suite"]
+    torrent_prefix = "dists_" + codename + "_"
     torrent_suffix = "_Packages-torrent.gz"
+    link_prefix = "dists_" + suite + "_"
     
     for component in release_headers.get("Components", "").split():
         # Get the old 'all' data
         all_file = torrent_prefix + component + "_binary-all" + torrent_suffix
+        all_link_file = None
+        if suite != codename:
+            all_link_file = link_prefix + component + "_binary-all" + torrent_suffix
         old_all_pieces, all_headers = get_old(all_file)
         all_pieces = {}
         all_new_pieces = []
@@ -354,6 +360,9 @@
     
         for arch in release_headers.get("Architectures", "").split():
             torrent_file = torrent_prefix + component + "_binary-" + arch + torrent_suffix
+            link_file = None
+            if suite != codename:
+                link_file = link_prefix + component + "_binary-" + arch + torrent_suffix
     
             # Find the Packages file that will be parsed
             found = False
@@ -366,6 +375,8 @@
                 print "WARNING: no matching Packages file for component %s, arch %s" % (component, arch)
                 if exists(torrent_file):
                     remove(torrent_file)
+                if link_file and exists(link_file):
+                    remove(link_file)
                 continue
             packages.pop(packages.index(filename))
     
@@ -394,14 +405,21 @@
                 # Add any new pieces to the end of pieces
                 add_new(pieces, new_pieces, headers)
                 
+            if len(pieces) > 2:
                 # Write the headers
                 print "writing ...",
                 sys.stdout.flush()
                 write_file(torrent_file, pieces, headers)
+                if link_file:
+                    if exists(link_file):
+                        remove(link_file)
+                    symlink(torrent_file, link_file)
             else:
                 print "empty ...",
                 if exists(torrent_file):
                     remove(torrent_file)
+                if link_file and exists(link_file):
+                    remove(link_file)
                 
             print "done."
     
@@ -420,14 +438,21 @@
             sys.stdout.flush()
             add_new(all_pieces, all_new_pieces, all_headers)
         
+        if len(all_pieces) > 2:
             # Write the all_headers
             print "writing ...",
             sys.stdout.flush()
             write_file(all_file, all_pieces, all_headers)
+            if all_link_file:
+                if exists(all_link_file):
+                    remove(all_link_file)
+                symlink(all_file, all_link_file)
         else:
             print "empty ...",
             if exists(all_file):
                 remove(all_file)
+            if all_link_file and exists(all_link_file):
+                remove(all_link_file)
     
         print "done."
     




More information about the Debtorrent-commits mailing list