r186 - in /debtorrent/trunk/DebTorrent: BT1/FileSelector.py BT1/makemetafile.py download_bt1.py
camrdale-guest at users.alioth.debian.org
camrdale-guest at users.alioth.debian.org
Sat Jul 28 00:02:01 UTC 2007
Author: camrdale-guest
Date: Sat Jul 28 00:02:01 2007
New Revision: 186
URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=186
Log:
Documentation.
Modified:
debtorrent/trunk/DebTorrent/BT1/FileSelector.py
debtorrent/trunk/DebTorrent/BT1/makemetafile.py
debtorrent/trunk/DebTorrent/download_bt1.py
Modified: debtorrent/trunk/DebTorrent/BT1/FileSelector.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/FileSelector.py?rev=186&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/FileSelector.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/FileSelector.py Sat Jul 28 00:02:01 2007
@@ -1,8 +1,10 @@
# Written by John Hoffman
# Modified by Cameron Dale
# see LICENSE.txt for license information
-
+#
# $Id$
+
+"""Enable the selective downloading of files within a torrent."""
from random import shuffle
import logging
@@ -14,8 +16,70 @@
class FileSelector:
+ """Enable the selective downloading of files within a torrent.
+
+ @type files: unknown
+ @ivar files: unknown
+ @type storage: unknown
+ @ivar storage: unknown
+ @type storagewrapper: unknown
+ @ivar storagewrapper: unknown
+ @type sched: unknown
+ @ivar sched: unknown
+ @type failfunc: unknown
+ @ivar failfunc: unknown
+ @type downloader: unknown
+ @ivar downloader: unknown
+ @type picker: unknown
+ @ivar picker: unknown
+ @type numfiles: unknown
+ @ivar numfiles: unknown
+ @type priority: unknown
+ @ivar priority: unknown
+ @type new_priority: unknown
+ @ivar new_priority: unknown
+ @type new_partials: unknown
+ @ivar new_partials: unknown
+ @type filepieces: unknown
+ @ivar filepieces: unknown
+ @type numpieces: unknown
+ @ivar numpieces: unknown
+ @type piece_priority: unknown
+ @ivar piece_priority: unknown
+ @type cancelfunc: unknown
+ @ivar cancelfunc: unknown
+ @type requestmorefunc: unknown
+ @ivar requestmorefunc: unknown
+ @type rerequestfunc: unknown
+ @ivar rerequestfunc: unknown
+ @type new_piece_priority: unknown
+ @ivar new_piece_priority: unknown
+
+ """
+
def __init__(self, files, piece_lengths, bufferdir,
storage, storagewrapper, sched, picker, failfunc):
+ """Initialize the instance.
+
+ @type files: unknown
+ @param files: unknown
+ @type piece_lengths: unknown
+ @param piece_lengths: unknown
+ @type bufferdir: unknown
+ @param bufferdir: unknown
+ @type storage: unknown
+ @param storage: unknown
+ @type storagewrapper: unknown
+ @param storagewrapper: unknown
+ @type sched: unknown
+ @param sched: unknown
+ @type picker: unknown
+ @param picker: unknown
+ @type failfunc: unknown
+ @param failfunc: unknown
+
+ """
+
self.files = files
self.storage = storage
self.storagewrapper = storagewrapper
@@ -56,6 +120,13 @@
def init_priority(self, new_priority):
+ """
+
+ @type new_priority: unknown
+ @param new_priority: unknown
+
+ """
+
try:
assert len(new_priority) == self.numfiles
for v in new_priority:
Modified: debtorrent/trunk/DebTorrent/BT1/makemetafile.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/BT1/makemetafile.py?rev=186&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/BT1/makemetafile.py (original)
+++ debtorrent/trunk/DebTorrent/BT1/makemetafile.py Sat Jul 28 00:02:01 2007
@@ -2,8 +2,19 @@
# multitracker extensions by John Hoffman
# Modified by Cameron Dale
# see LICENSE.txt for license information
-
+#
# $Id$
+
+"""Create a torrent file or data structure.
+
+ at type defaults: C{list} of (C{string}, unknown, C{string})
+ at var defaults: the default configuration variables, including descriptions
+ at type default_piece_len_exp: C{int}
+ at var default_piece_len_exp: the exponent of the default piece size to use
+ at type ignore: C{list} of C{string}
+ at var ignore: file names to ignore when creating torrents
+
+"""
from os.path import getsize, split, join, abspath, isdir
from os import listdir
@@ -50,6 +61,7 @@
ignore = ['core', 'CVS']
def print_announcelist_details():
+ """Print the configuration options for the announce list and deb mirrors."""
print (' announce_list = optional list of redundant/backup tracker URLs, in the format:')
print (' url[,url...][|url[,url...]...]')
print (' where URLs separated by commas are all tried first')
@@ -69,6 +81,18 @@
print (' url[|url...]')
def uniconvertl(l, e):
+ """Convert a list of strings to Unicode.
+
+ @type l: C{list} of C{string}
+ @param l: the strings to convert to unicode
+ @type e: C{string}
+ @param e: the encoding to use for converting the input data
+ @rtype: C{list} of C{string}
+ @return: the converted strings encoded in UTF-8
+ @raise UnicodeError: if a conversion error occurs
+
+ """
+
r = []
try:
for s in l:
@@ -78,6 +102,20 @@
return r
def uniconvert(s, e = None):
+ """Convert a string to Unicode.
+
+ @type s: C{string}
+ @param s: the string to convert to unicode
+ @type e: C{string}
+ @param e: the encoding to use for converting the input data
+ (optional, defaults to the current file system encoding, or ASCII if
+ it cannot be determined)
+ @rtype: C{string}
+ @return: the converted string encoded in UTF-8
+ @raise UnicodeError: if a conversion error occurs
+
+ """
+
if not e:
e = ENCODING
if not e:
@@ -90,7 +128,15 @@
return s.encode('utf-8')
def convert_all(f):
- # Find the architecture and replace it with 'all'
+ """Find the architecture and replace it with 'all'.
+
+ @type f: C{string}
+ @param f: the string to search and replace the architecture in
+ @rtype: C{string}
+ @return: the converted string
+
+ """
+
(f_all, n) = subn(r'binary-[a-zA-Z0-9]+([^a-zA-Z0-9]?)', r'binary-all\1', f)
if n == 0:
# Otherwise add '-all' before the extension
@@ -101,6 +147,19 @@
return f_all
def make_meta_file(file, url, params = {}, progress = lambda x: None):
+ """Create the torrent files from a Packages file.
+
+ @type file: C{string}
+ @param file: the Packages file to parse to create the torrent
+ @type url: C{string}
+ @param url: the announce address to use
+ @type params: C{dictionary}
+ @param params: the command-line parameters to use
+ @type progress: C{method}
+ @param progress: report the progress of the creation
+
+ """
+
if params.has_key('piece_size_pow2'):
piece_len_exp = params['piece_size_pow2']
else:
@@ -148,6 +207,21 @@
create_file(convert_all(f), info_all, url, uniconvert(convert_all(name), encoding), params)
def create_file(f, info, url, name, params):
+ """Actually write the torrent data to a file.
+
+ @type f: C{string}
+ @param f: the file name to write
+ @type info: C{dictionary}
+ @param info: the torrent data to write
+ @type url: C{string}
+ @param url: the announce address for the torrent
+ @type name: C{string}
+ @param name: the internal name of the torrent
+ @type params: C{dictionary}
+ @param params: the command-line parameters
+
+ """
+
check_info(info)
h = open(f, 'wb')
data = {'info': info, 'announce': strip(url),
@@ -174,6 +248,15 @@
h.close()
def calcsize(file):
+ """Calculate the size of a file/directory.
+
+ @type file: C{string}
+ @param file: the file/directory to calculate the size of
+ @rtype: C{long}
+ @return: the size of the file/directory
+
+ """
+
if not isdir(file):
return getsize(file)
total = 0L
@@ -182,6 +265,19 @@
return total
def getsubpieces(file, pieces_file = ''):
+ """Retrieve the sub-package piece imformation for the Packages file.
+
+ @type file: C{string}
+ @param file: the Packages file name to retrieve piece information for
+ @type pieces_file: C{string}
+ @param pieces_file: the file that contains the piece information
+ (optional, defaults to retrieving the info from the web)
+ @rtype: C{dictionary}
+ @return: the piece info, keys are the file names, values are tuples of
+ a list of piece SHA1 hashes and a list of piece sizes
+
+ """
+
pieces = {}
packages = 0
@@ -253,6 +349,28 @@
return pieces
def getpieces(f, encoding = None, progress = lambda x: None, separate_all = 0, sub_pieces = {}):
+ """Extract the piece information from the Packages file.
+
+ @type f: C{iterable}
+ @param f: the already opened file or file data as a list of strings
+ @type encoding: C{string}
+ @param encoding: the encoding to use for the file names
+ (optional, defaults to the default encoding, or ASCII)
+ @type progress: C{method}
+ @param progress: the method to call with updates on the progress
+ (optional, defaults to not printing progress updates)
+ @type separate_all: C{boolean}
+ @param separate_all: whether to separate the architecture:all packages into
+ a separate torrent (optional, defaults to False)
+ @type sub_pieces: C{dictionary}
+ @param sub_pieces: 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)
+ @rtype: (C{dictionary}, C{dictionary})
+ @return: the two torrents, the second is the architecture:all one, if that
+ was requested, otherwise it is None
+
+ """
if not encoding:
encoding = ENCODING
@@ -312,6 +430,27 @@
return (info, info_all)
def makeinfo(file, piece_length, encoding, progress, separate_all = 0, pieces_file = ''):
+ """
+
+ @type file: C{string}
+ @param file: the file name of the Packages file to make into a torrent
+ @type piece_length: C{int}
+ @param piece_length: not used
+ @type encoding: C{string}
+ @param encoding: the encoding to use for the file names
+ @type progress: C{method}
+ @param progress: the method to call with updates on the progress
+ @type separate_all: C{boolean}
+ @param separate_all: whether to separate the architecture:all packages into
+ a separate torrent (optional, defaults to False)
+ @type pieces_file: C{string}
+ @param pieces_file: the file that contains the piece information
+ (optional, defaults to retrieving the info from the web)
+ @rtype: (C{dictionary}, C{dictionary})
+ @return: the two torrents, the second is the architecture:all one, if that
+ was requested, otherwise it is None
+
+ """
sub_pieces = getsubpieces(file, pieces_file)
@@ -325,6 +464,18 @@
return (info, info_all)
def subfiles(d):
+ """Process a directory structure to find all the files in it.
+
+ Files in a directory are parsed first before the sub-directory files.
+
+ @type d: C{string}
+ @param d: the top-level directory to start at
+ @rtype: C{list} of (C{list} of C{string}, C{string})
+ @return: all the files found in the directory, both as a path list and a
+ file name
+
+ """
+
r = []
stack = [([], d)]
while len(stack) > 0:
@@ -339,6 +490,23 @@
def completedir(dir, url, params = {}, vc = lambda x: None, fc = lambda x: None):
+ """Create a torrent for each file in a directory.
+
+ Does not recurse into sub-directories.
+
+ @type dir: C{string}
+ @param dir: the directory to find files in
+ @type url: C{string}
+ @param url: the announce address to use for the torrents
+ @type params: unknown
+ @param params: unknown
+ @type vc: C{method}
+ @param vc: progress report while the torrent generation is underway
+ @type fc: C{method}
+ @param fc: progress report when a new torrent generation is started
+
+ """
+
files = listdir(dir)
files.sort()
ext = '.dtorrent'
Modified: debtorrent/trunk/DebTorrent/download_bt1.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/download_bt1.py?rev=186&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/download_bt1.py (original)
+++ debtorrent/trunk/DebTorrent/download_bt1.py Sat Jul 28 00:02:01 2007
@@ -6,7 +6,7 @@
"""Manage a single download.
- at type defaults: C{list} of C{tuple}
+ at type defaults: C{list} of (C{string}, unknown, C{string})
@var defaults: the default configuration variables, including descriptions
@type argslistheader: C{string}
@var argslistheader: the header to print before the default config
More information about the Debtorrent-commits
mailing list