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

Class ConfigDir

source code

Manage configuration and cache files.

Instance Methods [hide private]
 
__init__(self, config_type=None)
Initialize the instance, create directories and file names.
source code
    Config Handling
 
setDefaults(self, defaults, ignore=[])
Set the default values to use for the configuration.
source code
 
setCacheDir(self, cache_dir, create_dirs=True)
Sets the various cache directory locations.
source code
boolean
checkConfig(self, configfile)
Check if a config file already exists.
source code
 
loadConfigFile(self, configfile)
Load a configuration from a config file.
source code
dictionary
loadConfig(self, params)
Load the configuration from any config files.
source code
boolean
saveConfig(self, new_config=None)
Sets and writes to the file the new configuration.
source code
dictionary
getConfig(self)
Get the current configuration variables.
source code
    State
dictionary
getState(self)
Get the state from the state file.
source code
boolean
saveState(self, state)
Saves the state to the state file.
source code
    Torrent Files
list of string
getTorrents(self)
Get a list of the torrents that have cache data.
source code
list of int
getTorrentVariations(self, t)
Get the torrent variations in the cache data for a given hash.
source code
string
getTorrentFile(self, t, v=-1)
Get the undecoded torrent file for the hash.
source code
dictionary
getTorrent(self, t, v=-1)
Get the torrent data for the hash.
source code
int
writeTorrent(self, data, t, v=-1)
Save the torrent data.
source code
    Torrent Data
dictionary
getTorrentData(self, t)
Retrieve cached data for a torrent.
source code
boolean
writeTorrentData(self, t, data)
Write cached data for a torrent.
source code
 
deleteTorrentData(self, t)
Delete the cached data for a torrent.
source code
string
getPieceDir(self, t)
Get the directory to save temporary pieces for a torrent.
source code
    Expire Cache
 
deleteOldCacheData(self, days, still_active=[], delete_torrents=True)
Delete old cache data after a period of time.
source code
 
deleteOldTorrents(self, days, still_active=[])
Delete old cached data and torrents after a period of time.
source code
Instance Variables [hide private]
dictionary TorrentDataBuffer
any torrent data read/written, keys are the torrent info hashes, values are the torrent data (dictionary)
string cache_dir
the directory to save cache files in
dictionary config
the current configuration variables
string config_type
the extension to include in the saved files' names
string configfile
the file name for the saved configuration data
string dir_datacache
the directory to save stopped torrent's state in
string dir_piececache
the directory to store temporary piece files in
string dir_torrentcache
the directory to save torrent files in
string home_dir
the user's home directory
string statefile
the file name for the saved state
Method Details [hide private]

__init__(self, config_type=None)
(Constructor)

source code 
Initialize the instance, create directories and file names.
Parameters:
  • config_type (string) - the extension to include in the saved files' names (optional, default is to use no extension)

setDefaults(self, defaults, ignore=[])

source code 
Set the default values to use for the configuration.
Parameters:
  • defaults (dictionary) - the default config values
  • ignore (list) - the keys in the defaults to ignore (optional, default is to ignore none of them)

setCacheDir(self, cache_dir, create_dirs=True)

source code 
Sets the various cache directory locations.
Parameters:
  • cache_dir (string) - the directory to save cache files in
  • create_dirs (boolean) - whether to create the client cache directories (optional, defaults to True)

checkConfig(self, configfile)

source code 
Check if a config file already exists.
Parameters:
  • configfile (string) - the config file to use
Returns: boolean
whether the config file exists

loadConfigFile(self, configfile)

source code 
Load a configuration from a config file.
Parameters:
  • configfile (string) - the config file to use

loadConfig(self, params)

source code 
Load the configuration from any config files.
Parameters:
  • params (list of strings) - a list of the command-line arguments
Returns: dictionary
the loaded configuration variables
Raises:
  • IOError - if the specified config file can not be found

saveConfig(self, new_config=None)

source code 
Sets and writes to the file the new configuration.
Parameters:
  • new_config (dictionary) - the configuration to set and write (optional, default is to use the previously set one)
Returns: boolean
whether writing to the file was successful

getConfig(self)

source code 
Get the current configuration variables.
Returns: dictionary
the current configuration variables

getState(self)

source code 
Get the state from the state file.
Returns: dictionary
the previosuly saved state, or None if there was no previously saved state

saveState(self, state)

source code 
Saves the state to the state file.
Parameters:
  • state (dictionary) - the state to save
Returns: boolean
whether the saving was successful

getTorrents(self)

source code 
Get a list of the torrents that have cache data.
Returns: list of string
the torrent hashes found

getTorrentVariations(self, t)

source code 
Get the torrent variations in the cache data for a given hash.
Parameters:
  • t (string) - the torrent hash to check for
Returns: list of int
the variations of the hash found

getTorrentFile(self, t, v=-1)

source code 
Get the undecoded torrent file for the hash.
Parameters:
  • t (string) - the torrent hash to lookup
  • v (int) - the variation to get (optional, default is the largest)
Returns: string
the contents of the torrent file

getTorrent(self, t, v=-1)

source code 
Get the torrent data for the hash.
Parameters:
  • t (string) - the torrent hash to lookup
  • v (int) - the variation to get (optional, default is the largest)
Returns: dictionary
the torrent metainfo found

writeTorrent(self, data, t, v=-1)

source code 
Save the torrent data.
Parameters:
  • data (dictionary) - the torrent metainfo
  • t (string) - the hash of the torrent metainfo
  • v (int) - the variation to save as, or None for no variation (optional, default is the next after the largest)
Returns: int
the variation used, or None if the write failed

getTorrentData(self, t)

source code 
Retrieve cached data for a torrent.
Parameters:
  • t (string) - the info hash to retrieve cached data for
Returns: dictionary
the bdecoded cached data

writeTorrentData(self, t, data)

source code 
Write cached data for a torrent.
Parameters:
  • t (string) - the info hash to write cached data for
  • data (dictionary) - the data to cache
Returns: boolean
whether the write was successful

deleteTorrentData(self, t)

source code 
Delete the cached data for a torrent.
Parameters:
  • t (string) - the info hash to delete the cached data of

getPieceDir(self, t)

source code 
Get the directory to save temporary pieces for a torrent.
Parameters:
  • t (string) - the info hash to get the piece cache data of
Returns: string
the directory to save temporary pieces in

deleteOldCacheData(self, days, still_active=[], delete_torrents=True)

source code 
Delete old cache data after a period of time.
Parameters:
  • days (int) - the number of days to delete cached data after
  • still_active (list of string) - the hashes of torrents that are still running (optional, default is to delete all torrent's cached data)
  • delete_torrents (boolean) - whether to delete the torrent files as well

deleteOldTorrents(self, days, still_active=[])

source code 
Delete old cached data and torrents after a period of time.
Parameters:
  • days (int) - the number of days to delete cached data after
  • still_active (list of string) - the hashes of torrents that are still running (optional, default is to delete all torrent's cached data)