Package DebTorrent :: Package BT1 :: Module FileSelector :: Class FileSelector
[hide private]
[frames] | no frames]

Class FileSelector

source code

Enable the selective downloading of files within a torrent.

Instance Methods [hide private]
 
__init__(self, files, piece_lengths, bufferdir, storage, storagewrapper, sched, picker, failfunc)
Initialize the instance.
source code
boolean
init_priorities(self, init_priority)
Initialize the priorities of all the files from the unpickled state.
source code
 
unpickle(self, d)
Unpickle the previously saved state.
source code
 
tie_in(self, cancelfunc, requestmorefunc, rerequestfunc)
Set some instance variables that weren't available at initialization.
source code
boolean
_set_files_disabled(self, old_priority, new_priority)
Disable files based on a new priority setting.
source code
list of int
_get_piece_priority_list(self, file_priority_list)
Create a piece priority list from a file priority list.
source code
list of int
_initialize_piece_priority(self, new_priority)
Initialize the piece priorities on startup.
source code
list of int
_set_piece_priority(self, new_priority)
Disable pieces base on a new file priority setting.
source code
 
set_priorities_now(self, new_priority=None)
Set the new priorities.
source code
 
set_priorities(self, new_priority)
Schedule the future setting of the new priorities.
source code
 
set_priority(self, f, p)
Set the priority of a single file.
source code
list of int
get_priorities(self)
Get the current (or soon to be set) file priorities.
source code
 
__setitem__(self, index, val)
Set the priority for the file.
source code
int
__getitem__(self, index)
Get the priority for the file.
source code
 
finish(self)
Delete disabled files when the download is being shutdown.
source code
dictionary
pickle(self)
Pickle the current state for later.
source code
Instance Variables [hide private]
method cancelfunc
method to call to cancel piece downloads
unknown downloader
not used
method failfunc
the method to call to indicate an error has occurred
list of tuple filepieces
an ordered list, one for each file, containing a tuple of the pieces that belong to that file
list of (list of string, long) files
the paths and sizes of the files
list of int init_priority
the initial unpickled priority of each file in the download
list of int new_partials
the new list of partially completed pieces to process
list of int new_priority
the new priority of each file in the download
int numfiles
the number of files in the download
int numpieces
the number of pieces in the download
PiecePicker.PiecePicker picker
the PiecePicker instance to use
list of int piece_priority
the current priority for each piece in the download
list of int priority
the current priority of each file in the download:
method requestmorefunc
method to call to request more peers for a newly enabled piece download
method rerequestfunc
method to call to request more peers
method sched
the mehtod to call to schedule a future invocation of a function
Storage.Storage storage
the Storage instance to use
StorageWrapper.StorageWrapper storagewrapper
the StorageWrapper instance to use
Method Details [hide private]

__init__(self, files, piece_lengths, bufferdir, storage, storagewrapper, sched, picker, failfunc)
(Constructor)

source code 
Initialize the instance.
Parameters:
  • files (list of (list of string, long)) - the paths and sizes of the files
  • piece_lengths (list of int) - the sizes of the pieces
  • bufferdir (string) - the directory to store the buffered pieces in
  • storage (Storage.Storage) - the Storage instance to use
  • storagewrapper (StorageWrapper.StorageWrapper) - the StorageWrapper instance to use
  • sched (method) - the mehtod to call to schedule a future invocation of a function
  • picker (PiecePicker.PiecePicker) - the PiecePicker instance to use
  • failfunc (method) - the method to call to indicate an error has occurred

init_priorities(self, init_priority)

source code 
Initialize the priorities of all the files from the unpickled state.
Parameters:
  • init_priority (list of int) - the new file priorities
Returns: boolean
whether the initialization was successful

unpickle(self, d)

source code 

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:
   -1 -- download disabled
    0 -- highest
    1 -- normal
    2 -- lowest

Any files not listed are assumed to have a priority of -1 (download disabled).

Also see Storage.pickle and StorageWrapper.pickle for additional keys.
Parameters:
  • d (dictionary) - the pickled state data

tie_in(self, cancelfunc, requestmorefunc, rerequestfunc)

source code 
Set some instance variables that weren't available at initialization.
Parameters:
  • cancelfunc (method) - method to call to cancel piece downloads
  • requestmorefunc (method) - method to call to request more peers for a newly enabled piece download
  • rerequestfunc (method) - method to call to request more peers

_set_files_disabled(self, old_priority, new_priority)

source code 
Disable files based on a new priority setting.
Parameters:
  • old_priority (list of int) - the old file priorities
  • new_priority (list of int) - the new file priorities
Returns: boolean
whether the disabling was successful

_get_piece_priority_list(self, file_priority_list)

source code 
Create a piece priority list from a file priority list.
Parameters:
  • file_priority_list (list of int) - the file priorities
Returns: list of int
the new piece priorities

_initialize_piece_priority(self, new_priority)

source code 
Initialize the piece priorities on startup.
Parameters:
  • new_priority (list of int) - the new file priorities
Returns: list of int
the new piece priorities

_set_piece_priority(self, new_priority)

source code 
Disable pieces base on a new file priority setting.
Parameters:
  • new_priority (list of int) - the new file priorities
Returns: list of int
the new piece priorities

set_priorities_now(self, new_priority=None)

source code 
Set the new priorities.
Parameters:
  • new_priority (list of int) - the new file priorities (optional, defaults to using the saved new_priority)

set_priorities(self, new_priority)

source code 
Schedule the future setting of the new priorities.
Parameters:
  • new_priority (list of int) - the new file priorities

set_priority(self, f, p)

source code 
Set the priority of a single file.
Parameters:
  • f (int) - the index of the file to set the priority of
  • p (int) - the new priority for the file

get_priorities(self)

source code 
Get the current (or soon to be set) file priorities.
Returns: list of int
the current file priorities

__setitem__(self, index, val)
(Index assignment operator)

source code 
Set the priority for the file.
Parameters:
  • index (int) - the index of the file to set the priority of
  • val (int) - the new priority for the file

__getitem__(self, index)
(Indexing operator)

source code 
Get the priority for the file.
Parameters:
  • index (int) - the index of the file to get the priority of
Returns: int
the priority for the file

pickle(self)

source code 
Pickle the current state for later.
Returns: dictionary
the pickled data

See Also: unpickle


Instance Variable Details [hide private]

priority

the current priority of each file in the download:
   -1 -- do not download
    0 -- highest priority
    1 -- medium priority
    2 -- lowest priority
Type:
list of int