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

Module makemetafile

source code

Create a torrent file or data structure.

Classes [hide private]
  TorrentCreator
Create a torrent metainfo from a downloaded Packages file (threaded).
Functions [hide private]
 
print_announcelist_details()
Print the configuration options for the announce list and deb mirrors.
source code
list of string
uniconvertl(l, e)
Convert a list of strings to Unicode.
source code
string
uniconvert(s, e=None)
Convert a string to Unicode.
source code
string
convert_all(f)
Find the architecture and replace it with 'all'.
source code
 
make_meta_file(file, params={}, progress=<function <lambda> at 0x2b5519938f50>)
Create the torrent files from a Packages file.
source code
 
create_file(f, info, name, params, ordering_headers)
Actually write the torrent data to a file.
source code
long
calcsize(file)
Calculate the size of a file/directory.
source code
dictionary
getsubpieces(file, pieces_file='')
Retrieve the sub-package piece information for the Packages file.
source code
dictionary
getordering(file, torrent_file='', all=True)
Retrieve unique piece piece ordering information for the Packages file.
source code
dictionary
orderpieces(fs, pieces, lengths, separate_all=1, piece_ordering={}, num_pieces=0)
Order the pieces appropriately in the info dictionary.
source code
(dictionary, dictionary)
getpieces(f, encoding=None, progress=<function <lambda> at 0x2b5519941320>, separate_all=1, sub_pieces={}, piece_ordering={}, piece_ordering_all={}, num_pieces=0, num_all_pieces=0)
Extract the piece information from the Packages file.
source code
(dictionary, dictionary, dictionary, dictionary)
makeinfo(file, piece_length, encoding, progress, separate_all=1, pieces_file='', torrent_file='', torrent_all_file='')
Open the file and pass it to the getpieces function.
source code
list of (list of string, string)
subfiles(d)
Process a directory structure to find all the files in it.
source code
 
completedir(dir, params={}, vc=<function <lambda> at 0x2b5519941578>, fc=<function <lambda> at 0x2b55199415f0>)
Create a torrent for each file in a directory.
source code
Variables [hide private]
  ENCODING = 'UTF-8'
logging.Logger logger = logging.getLogger('DebTorrent.BT1.makemetafile')
the logger to send all log messages to for this module
list of (string, unknown, string) defaults = [('announce', '', 'the announce URL to use for the ...
the default configuration variables, including descriptions
int default_piece_len_exp = 18
the exponent of the default piece size to use
list of string ignore = ['core', 'CVS']
file names to ignore when creating torrents

Imports: os.path.getsize, os.path.split, os.path.join, os.path.abspath, os.path.isdir, os.listdir, sha.sha, copy.copy, string.strip, bencode.bencode, btformats.check_info, btformats.check_message, threading.Event, threading.Thread, time.time, traceback.print_exc, zurllib.urlopen, gzip, bz2.decompress, StringIO.StringIO, re.subn, binascii, logging, sys.getfilesystemencoding, sys.getdefaultencoding


Function Details [hide private]

uniconvertl(l, e)

source code 
Convert a list of strings to Unicode.
Parameters:
  • l (list of string) - the strings to convert to unicode
  • e (string) - the encoding to use for converting the input data
Returns: list of string
the converted strings encoded in UTF-8
Raises:
  • UnicodeError - if a conversion error occurs

uniconvert(s, e=None)

source code 
Convert a string to Unicode.
Parameters:
  • s (string) - the string to convert to unicode
  • e (string) - the encoding to use for converting the input data (optional, defaults to the current file system encoding, or ASCII if it cannot be determined)
Returns: string
the converted string encoded in UTF-8
Raises:
  • UnicodeError - if a conversion error occurs

convert_all(f)

source code 
Find the architecture and replace it with 'all'.
Parameters:
  • f (string) - the string to search and replace the architecture in
Returns: string
the converted string

make_meta_file(file, params={}, progress=<function <lambda> at 0x2b5519938f50>)

source code 
Create the torrent files from a Packages file.
Parameters:
  • file (string) - the Packages file to parse to create the torrent
  • params (dictionary) - the command-line parameters to use
  • progress (method) - report the progress of the creation

create_file(f, info, name, params, ordering_headers)

source code 
Actually write the torrent data to a file.
Parameters:
  • f (string) - the file name to write
  • info (dictionary) - the torrent data to write
  • name (string) - the internal name of the torrent
  • params (dictionary) - the command-line parameters
  • ordering_headers (dictionary) - the headers from the ordering file for the torrent
Raises:
  • ValueError - if the data is not correct

calcsize(file)

source code 
Calculate the size of a file/directory.
Parameters:
  • file (string) - the file/directory to calculate the size of
Returns: long
the size of the file/directory

getsubpieces(file, pieces_file='')

source code 
Retrieve the sub-package piece information for the Packages file.
Parameters:
  • file (string) - the Packages file name to retrieve piece information for
  • pieces_file (string) - the file that contains the piece information (optional, defaults to retrieving the info from the web)
Returns: dictionary
the piece info, keys are the file names, values are tuples of a list of piece SHA1 hashes and a list of piece sizes

getordering(file, torrent_file='', all=True)

source code 
Retrieve unique piece piece ordering information for the Packages file.
Parameters:
  • file (string) - the Packages file name to retrieve piece ordering information for
  • torrent_file (string) - the file that contains the piece ordering information (optional, defaults to retrieving the info from the web)
  • all (boolean) - whether to get it for the architecture, or for arch:all (optional, defaults to the specific architecture)
Returns: dictionary
the piece ordering info, keys are the starting piece numbers to use for the files, values are the file names

orderpieces(fs, pieces, lengths, separate_all=1, piece_ordering={}, num_pieces=0)

source code 
Order the pieces appropriately in the info dictionary.
Parameters:
  • fs (dictionary) - the files data for the torrent, keys are the file names from the Packages file, values are the dictionaries to use for them in the torrent
  • pieces (dictionary) - piece hashes for the torrent, keys are the file names from the Packages file, values are lists of the piece hashes for the file
  • lengths (dictionary) - lengths of the pieces for the torrent, keys are the file names from the Packages file, values are lists of the piece lengths
  • separate_all (boolean) - whether to separate the architecture:all packages into a separate torrent (optional, defaults to True)
  • piece_ordering (dictionary) - the piece ordering info to use for the torrent (optional, defaults to being ordered by file name)
  • num_pieces (int) - the number of pieces in the piece ordering (optional, but must be specified if using ordering data)
Returns: dictionary
the properly ordered info section of the torrent

getpieces(f, encoding=None, progress=<function <lambda> at 0x2b5519941320>, separate_all=1, sub_pieces={}, piece_ordering={}, piece_ordering_all={}, num_pieces=0, num_all_pieces=0)

source code 
Extract the piece information from the Packages file.
Parameters:
  • f (iterable) - the already opened file or file data as a list of strings
  • encoding (string) - the encoding to use for the file names (optional, defaults to the default encoding, or ASCII)
  • progress (method) - the method to call with updates on the progress (optional, defaults to not printing progress updates)
  • separate_all (boolean) - whether to separate the architecture:all packages into a separate torrent (optional, defaults to True)
  • sub_pieces (dictionary) - the sub-package piece info, keys are the file names, values are tuples of a list of piece SHA1 hashes and a list of piece sizes (optional, defaults to not using sub-package pieces)
  • piece_ordering (dictionary) - the piece ordering info to use for the architecture specific torrent (optional, defaults to being ordered by file name)
  • piece_ordering_all (dictionary) - the piece ordering info to use for the architecture:all torrent (optional, defaults to being ordered by file name)
  • num_pieces (int) - the number of pieces in the piece ordering for the architecture specific torrent (optional, but must be specified if using ordering data)
  • num_all_pieces (int) - the number of pieces in the piece ordering for the architecture:all torrent (optional, but must be specified if using ordering data)
Returns: (dictionary, dictionary)
the two torrents, the second is the architecture:all one, if that was requested, otherwise it is None

makeinfo(file, piece_length, encoding, progress, separate_all=1, pieces_file='', torrent_file='', torrent_all_file='')

source code 
Open the file and pass it to the getpieces function.
Parameters:
  • file (string) - the file name of the Packages file to make into a torrent
  • piece_length (int) - not used
  • encoding (string) - the encoding to use for the file names
  • progress (method) - the method to call with updates on the progress
  • separate_all (boolean) - whether to separate the architecture:all packages into a separate torrent (optional, defaults to True)
  • pieces_file (string) - the file that contains the piece information (optional, defaults to retrieving the info from the web)
  • torrent_file (string) - the file that contains the piece ordering information (optional, defaults to retrieving the info from the web)
  • torrent_all_file (string) - the file that contains the piece ordering information for arch:all (optional, defaults to retrieving the info from the web)
Returns: (dictionary, dictionary, dictionary, dictionary)
the two torrents, the second is the architecture:all one, if that was requested, otherwise it is None, followed by the ordering headers for the torrents

subfiles(d)

source code 

Process a directory structure to find all the files in it.

Files in a directory are parsed first before the sub-directory files.
Parameters:
  • d (string) - the top-level directory to start at
Returns: list of (list of string, string)
all the files found in the directory, both as a path list and a file name

completedir(dir, params={}, vc=<function <lambda> at 0x2b5519941578>, fc=<function <lambda> at 0x2b55199415f0>)

source code 

Create a torrent for each file in a directory.

Does not recurse into sub-directories.
Parameters:
  • dir (string) - the directory to find files in
  • params (dictionary) - the configuration options (optional, defaults to None)
  • vc (method) - progress report while the torrent generation is underway
  • fc (method) - progress report when a new torrent generation is started

Variables Details [hide private]

defaults

the default configuration variables, including descriptions
Type:
list of (string, unknown, string)
Value:
[('announce', '', 'the announce URL to use for the torrent'),
 ('announce_list', '', 'a list of announce URLs - explained below'),
 ('deb_mirrors', '', 'a list of mirror URLs - explained below'),
 ('piece_size_pow2',
  0,
  'which power of 2 to set the piece size to (0 = automatic)'),
 ('comment',
  '',
...