r410 - /debtorrent/trunk/DebTorrent/BT1/track.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Sun Jan 11 04:26:15 UTC 2009


Author: camrdale-guest
Date: Sun Jan 11 04:26:15 2009
New Revision: 410

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=410
Log:
Add a global stats entry to the state file.

Modified:
    debtorrent/trunk/DebTorrent/BT1/track.py

Modified: debtorrent/trunk/DebTorrent/BT1/track.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/track.py?rev=410&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/track.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/track.py Sun Jan 11 04:26:15 2009
@@ -161,7 +161,7 @@
                     if type(info.get('requirecrypto')) not in (IntType,LongType):
                         raise ValueError
         elif cname == 'stats':
-            if (type(cinfo) != DictType): # The 'stats' key is a dictionary of SHA hashes (torrent ids)
+            if (type(cinfo) != DictType): # The 'stats' key is a dictionary of SHA hashes (and the special key 'global')
                 raise ValueError          # ... for keeping track of the total completions per torrent
             for y in cinfo.values():      # ... each torrent has an integer value
                 if type(y) != DictType:
@@ -223,10 +223,25 @@
                                                     'uploaded': 0}
                     del tempstate['completed']
                 tempstate['version'] = 1
-                logger.info('successfully upgraded the previous state file')
+                version = 1
+                logger.info('successfully upgraded to state file v1')
             except:
                 logger.exception('old statefile corrupt; resetting')
                 tempstate = {'version': 1}
+                version = 1
+
+        if version < 2:
+            try:
+                tempstate['stats']['global'] = {'completed': 0,
+                                                'downloaded': 0,
+                                                'uploaded': 0}
+                tempstate['version'] = 2
+                version = 2
+                logger.info('successfully upgraded to state file v2')
+            except:
+                logger.exception('old statefile corrupt; resetting')
+                tempstate = {'version': 2}
+                version = 2
 
         # Test the state to make sure it's not been corrupted
         try:




More information about the Debtorrent-commits mailing list