r347 - in /debtorrent/trunk/DebTorrent/BT1: FileSelector.py Storage.py
camrdale-guest at users.alioth.debian.org
camrdale-guest at users.alioth.debian.org
Thu Jan 24 00:43:09 UTC 2008
Author: camrdale-guest
Date: Thu Jan 24 00:43:09 2008
New Revision: 347
URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=347
Log:
Change the pickling to use dictionaries instead of lists of file names and their characteristics.
Modified:
debtorrent/trunk/DebTorrent/BT1/FileSelector.py
debtorrent/trunk/DebTorrent/BT1/Storage.py
Modified: debtorrent/trunk/DebTorrent/BT1/FileSelector.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/FileSelector.py?rev=347&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/FileSelector.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/FileSelector.py Thu Jan 24 00:43:09 2008
@@ -177,10 +177,10 @@
"""Unpickle the previously saved state.
Data is in the format::
- d['priority'] = [file name, priority, {file name, priority, ...}]
-
- It is a list of file names and their corrseponding download priorities
- for each file. The priority must be::
+ d['priority'] = {file name: priority, file name: priority, ...}
+
+ It is a dictionary of file names and their corrseponding download
+ priorities for each file. The priority must be::
-1 -- download disabled
0 -- highest
1 -- normal
@@ -198,13 +198,7 @@
if d.has_key('priority'):
try:
- # Create a dictionary of the saved file priorities
- saved_files = {}
- l = d['priority']
- assert len(l) % 2 == 0
- l = [l[x:x+2] for x in xrange(0,len(l),2)]
- for file, priority in l:
- saved_files[file] = priority
+ saved_files = d['priority']
# Create the new file priorities list from the saved ones
new_priority = []
@@ -503,15 +497,15 @@
"""
- files = []
+ files = {}
for i in xrange(len(self.priority)):
if not self.files[i][1]: # length == 0
continue
if self.priority[i] == -1:
continue
- files.extend([self.files[i][0], self.priority[i]])
-
- logger.info('Found %d files that need priority pickling' % len(files))
+ files[self.files[i][0]] = self.priority[i]
+
+ logger.info('Found %d files that need priority pickling' % len(files.keys()))
d = {'priority': files}
try:
s = self.storage.pickle()
Modified: debtorrent/trunk/DebTorrent/BT1/Storage.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/Storage.py?rev=347&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/Storage.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/Storage.py Thu Jan 24 00:43:09 2008
@@ -815,7 +815,7 @@
Pickled data format::
- d['files'] = [ file name, size, mtime {, file name, size, mtime...} ]
+ d['files'] = {file name: [size, mtime], file name: [size, mtime], ...}
file name in torrent, and the size and last modification
time for those files. Missing files are either empty
or disabled.
@@ -825,14 +825,14 @@
"""
- files = []
+ files = {}
for i in xrange(len(self.files)):
if not self.files[i][1]: # length == 0
continue
if self.disabled[i]:
continue
file = self.files[i][0]
- files.extend([file,getsize(file),int(getmtime(file))])
+ files[file] = [getsize(file), int(getmtime(file))]
return {'files': files}
@@ -849,12 +849,7 @@
"""
try:
- files = {}
- l = data['files']
- assert len(l) % 3 == 0
- l = [l[x:x+3] for x in xrange(0,len(l),3)]
- for file, size, mtime in l:
- files[file] = (size, mtime)
+ files = data['files']
logger.debug('saved file characteristics: %r', files)
valid_pieces = {}
@@ -875,7 +870,7 @@
def test(old, size, mtime):
"""Test that the file has not changed since the status save.
- @type old: C{tuple} of (C{long}, C{long})
+ @type old: C{list} of [C{long}, C{long}]
@param old: the previous size and modification time of the file
@type size: C{long}
@param size: the current size of the file
More information about the Debtorrent-commits
mailing list