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

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


Author: camrdale-guest
Date: Thu Aug  9 23:28:49 2007
New Revision: 213

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=213
Log:
Make uniquely remove old torrent files.

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=213&op=diff
==============================================================================
--- debtorrent/branches/unique/uniquely.py (original)
+++ debtorrent/branches/unique/uniquely.py Thu Aug  9 23:28:49 2007
@@ -7,6 +7,8 @@
 import gzip
 from bz2 import BZ2File
 from math import ceil
+from os import remove
+from os.path import exists
 
 # Some default values
 default_piecesize = 512*1024
@@ -56,7 +58,9 @@
         
         f.close()
     except:
-        # Just return the empty variables, causing a new torrent to be generated
+        # Delete the file and return empty variables to create a new torrent
+        if exists(old_file):
+            remove(old_file)
         pass
     
     return pieces, headers
@@ -249,6 +253,8 @@
         all_headers["Torrent"] = sha1.hexdigest()
 
     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:
@@ -258,12 +264,13 @@
                 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
-        torrent_file = torrent_prefix + component + "_binary-" + arch + torrent_suffix
-        print torrent_file + ": reading ... ",
+        print torrent_file + ": reading ...",
         sys.stdout.flush()
         old_files, headers = get_old(torrent_file)
 
@@ -299,7 +306,7 @@
             headers["Torrent"] = sha1.hexdigest()
 
         # Parse the Packages file for the new data
-        print "updating ... ",
+        print "updating ...",
         sys.stdout.flush()
         new_pieces = get_new(filename, old_files, headers, old_all_files, 
                              all_pieces, all_new_pieces)
@@ -309,7 +316,7 @@
 
         if new_pieces:
             # Write the headers
-            print "writing ... ",
+            print "writing ...",
             sys.stdout.flush()
             f = gzip.open(torrent_file, 'w')
             for header in header_order:
@@ -325,16 +332,21 @@
                 f.write(format_string % (piece, new_pieces[piece]))
             
             f.close()
+        else:
+            print "empty ...",
+            if exists(torrent_file):
+                remove(torrent_file)
+            
         print "done."
 
-    print all_file + ": ",
+    print all_file + ": reading ...",
     if new_all_torrent:
         print "new torrent created ...",
     sys.stdout.flush()
     # If there were 'all' files found
     if all_pieces or all_new_pieces:
         # Process the new 'all' files found
-        print "updating ... ",
+        print "updating ...",
         sys.stdout.flush()
         next_piece = int(all_headers["NextPiece"])
         piece_size = int(all_headers["PieceSize"])
@@ -357,7 +369,7 @@
         all_headers.setdefault("OriginalPieces", all_headers["NextPiece"])
     
         # Write the all_headers
-        print "writing ... ",
+        print "writing ...",
         sys.stdout.flush()
         f = gzip.open(all_file, 'w')
         for header in header_order:
@@ -373,6 +385,10 @@
             f.write(format_string % (piece, all_pieces[piece]))
         
         f.close()
+    else:
+        print "empty ...",
+        if exists(all_file):
+            remove(all_file)
 
     print "done."
 




More information about the Debtorrent-commits mailing list