r212 - /debtorrent/branches/unique/uniquely.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Thu Aug 9 22:28:09 UTC 2007


Author: camrdale-guest
Date: Thu Aug  9 22:28:09 2007
New Revision: 212

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=212
Log:
Change uniquely so a new torrent is created if some of the Release file fields change.

Modified:
    debtorrent/branches/unique/uniquely.py

Modified: debtorrent/branches/unique/uniquely.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/uniquely.py?rev=212&op=diff
==============================================================================
--- debtorrent/branches/unique/uniquely.py (original)
+++ debtorrent/branches/unique/uniquely.py Thu Aug  9 22:28:09 2007
@@ -11,6 +11,7 @@
 # Some default values
 default_piecesize = 512*1024
 extension = ".gz"
+# can not contain Date, Infohash, NextPiece or OriginalPieces
 default_hash_fields = ["Codename", "Suite", "Component", "Architecture",
                        "PieceSize", "OriginalDate"]
 header_order = ["Torrent", "Infohash", "OriginalDate", "Date", "PieceSize",
@@ -215,6 +216,7 @@
     old_all_files, all_headers = get_old(all_file)
     all_pieces = {}
     all_new_pieces = []
+    new_all_torrent = False
 
     # Create the all headers
     all_headers.setdefault("OriginalDate", date)
@@ -226,7 +228,21 @@
     all_headers["Component"] = component
     all_headers["Architecture"] = "all"
     all_headers.setdefault("TorrentHashFields", " ".join(default_hash_fields))
-    if "Torrent" not in all_headers:
+    
+    # Calculate the new hash
+    sha1 = sha.new()
+    for header in all_headers["TorrentHashFields"].split():
+        sha1.update(all_headers[header])
+    new_hash = sha1.hexdigest()
+
+    # Check if the hash has changed
+    if all_headers.get("Torrent", "") != new_hash:
+        # If it has, then reset the torrent
+        new_all_torrent = True
+        old_all_files = {}
+        all_headers["OriginalDate"] = date
+        all_headers["NextPiece"] = str(0)
+        all_headers.pop("OriginalPieces", "")
         sha1 = sha.new()
         for header in all_headers["TorrentHashFields"].split():
             sha1.update(all_headers[header])
@@ -261,7 +277,22 @@
         headers["Component"] = component
         headers["Architecture"] = arch
         headers.setdefault("TorrentHashFields", " ".join(default_hash_fields))
-        if "Torrent" not in headers:
+        
+        # Calculate the new hash
+        sha1 = sha.new()
+        for header in headers["TorrentHashFields"].split():
+            sha1.update(headers[header])
+        new_hash = sha1.hexdigest()
+        
+        # Check if the hash has changed
+        if headers.get("Torrent", "") != new_hash:
+            # If it has, then reset the torrent
+            print "new torrent created ...",
+            sys.stdout.flush()
+            old_files = {}
+            headers["OriginalDate"] = date
+            headers["NextPiece"] = str(0)
+            headers.pop("OriginalPieces", "")
             sha1 = sha.new()
             for header in headers["TorrentHashFields"].split():
                 sha1.update(headers[header])
@@ -273,6 +304,7 @@
         new_pieces = get_new(filename, old_files, headers, old_all_files, 
                              all_pieces, all_new_pieces)
 
+        # Set the final header values
         headers.setdefault("OriginalPieces", headers["NextPiece"])
 
         if new_pieces:
@@ -296,6 +328,8 @@
         print "done."
 
     print all_file + ": ",
+    if new_all_torrent:
+        print "new torrent created ...",
     sys.stdout.flush()
     # If there were 'all' files found
     if all_pieces or all_new_pieces:
@@ -318,7 +352,7 @@
             old_file = file
             old_size = size
     
-        # Set the new next piece to use
+        # Set the final header values
         all_headers["NextPiece"] = str(next_piece)
         all_headers.setdefault("OriginalPieces", all_headers["NextPiece"])
     




More information about the Debtorrent-commits mailing list