r222 - in /debtorrent/branches/unique: DebTorrent/BT1/AptListener.py DebTorrent/BT1/makemetafile.py DebTorrent/download_bt1.py DebTorrent/launchmanycore.py btcompletedir.py btmakemetafile.py test.py
camrdale-guest at users.alioth.debian.org
camrdale-guest at users.alioth.debian.org
Sun Aug 12 00:47:24 UTC 2007
Author: camrdale-guest
Date: Sun Aug 12 00:47:24 2007
New Revision: 222
URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=222
Log:
Use the new makemetafile piece ordering routines.
Modified:
debtorrent/branches/unique/DebTorrent/BT1/AptListener.py
debtorrent/branches/unique/DebTorrent/BT1/makemetafile.py
debtorrent/branches/unique/DebTorrent/download_bt1.py
debtorrent/branches/unique/DebTorrent/launchmanycore.py
debtorrent/branches/unique/btcompletedir.py
debtorrent/branches/unique/btmakemetafile.py
debtorrent/branches/unique/test.py
Modified: debtorrent/branches/unique/DebTorrent/BT1/AptListener.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/DebTorrent/BT1/AptListener.py?rev=222&op=diff
==============================================================================
--- debtorrent/branches/unique/DebTorrent/BT1/AptListener.py (original)
+++ debtorrent/branches/unique/DebTorrent/BT1/AptListener.py Sun Aug 12 00:47:24 2007
@@ -27,8 +27,8 @@
from time import time, gmtime, strftime
from DebTorrent.clock import clock
from sha import sha
-from binascii import b2a_hex
-from makemetafile import getpieces, getsubpieces, uniconvert, convert_all
+from binascii import a2b_hex, b2a_hex
+from makemetafile import getpieces, getsubpieces, getordering, uniconvert, convert_all
from DebTorrent.HTTPCache import HTTPCache
import os, logging
from DebTorrent.__init__ import version, product_name,version_short
@@ -503,23 +503,57 @@
return
sub_pieces = getsubpieces('_'.join(path))
-
- (info, info_all) = getpieces(h, separate_all = self.config['separate_all'], sub_pieces = sub_pieces)
+
+ (piece_ordering, ordering_headers) = getordering('_'.join(path))
+ if self.config['separate_all']:
+ (piece_ordering_all, ordering_all_headers) = getordering('_'.join(path), all = True)
+ else:
+ piece_ordering_all = {}
+ ordering_all_headers = {}
+
+ (info, info_all) = getpieces(h, separate_all = self.config['separate_all'],
+ sub_pieces = sub_pieces,
+ piece_ordering = piece_ordering,
+ piece_ordering_all = piece_ordering_all,
+ num_pieces = int(ordering_headers.get('NextPiece', 0)),
+ num_all_pieces = int(ordering_all_headers.get('NextPiece', 0)))
if info and self.config['separate_all'] in (0, 2, 3):
- self.start_torrent(info, name, path)
+ self.start_torrent(info, ordering_headers, name, path)
if info_all and self.config['separate_all'] in (1, 3):
- self.start_torrent(info_all, convert_all(name), path)
-
- def start_torrent(self, info, name, path):
+ self.start_torrent(info_all, ordering_all_headers, convert_all(name), path)
+
+ def start_torrent(self, info, headers, name, path):
+ """Start the torrent running.
+
+ @type info: C{dictionary}
+ @param info: the info dictionary to use for the torrent
+ @type headers: C{dictionary}
+ @param headers: the headers from the torrent file
+ @type name: C{string}
+ @param name: the name to use for the torrent
+ @type path: C{list} of C{string}
+ @param path: the path of the Packages file, starting with the mirror name
+
+ """
+
response = {'info': info,
- 'announce': self.config['default_tracker'],
+ 'announce': self.config['default_tracker'],
'name': uniconvert(name)}
+
+ if "Tracker" in headers:
+ response['announce'] = headers["Tracker"].strip()
+ del headers["Tracker"]
+ if "Torrent" in headers:
+ response['identifier'] = a2b_hex(headers["Torrent"].strip())
+ del headers["Torrent"]
+ for header, value in headers.items():
+ response[header] = value.strip()
if path.count('dists'):
mirror = 'http://' + '/'.join(path[:path.index('dists')]) + '/'
- response['deb_mirrors'] = [mirror]
+ response.setdefault('deb_mirrors', []).append(mirror)
infohash = sha(bencode(response['info'])).digest()
Modified: debtorrent/branches/unique/DebTorrent/BT1/makemetafile.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/DebTorrent/BT1/makemetafile.py?rev=222&op=diff
==============================================================================
--- debtorrent/branches/unique/DebTorrent/BT1/makemetafile.py (original)
+++ debtorrent/branches/unique/DebTorrent/BT1/makemetafile.py Sun Aug 12 00:47:24 2007
@@ -241,10 +241,10 @@
data['announce'] = ordering_headers["Tracker"].strip()
del ordering_headers["Tracker"]
if "Torrent" in ordering_headers:
- data['identifier'] = ordering_headers["Torrent"]
+ data['identifier'] = binascii.a2b_hex(ordering_headers["Torrent"].strip())
del ordering_headers["Torrent"]
for header, value in ordering_headers.items():
- data[header] = value
+ data[header] = value.strip()
if params.has_key('announce') and params['announce']:
data['announce'] = params['announce'].strip()
@@ -468,7 +468,7 @@
except:
pass
- logger.info('successfully retrieved torrent ordering data for '+str(len(pieces))+' pieces')
+ logger.info('successfully retrieved torrent ordering data for '+str(len(pieces))+' files')
return (pieces, headers)
@@ -642,7 +642,7 @@
def 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.
@type file: C{string}
@param file: the file name of the Packages file to make into a torrent
@@ -716,15 +716,13 @@
return r
-def completedir(dir, url, params = {}, vc = lambda x: None, fc = lambda x: None):
+def completedir(dir, 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: C{dictionary}
@param params: the configuration options (optional, defaults to None)
@type vc: C{method}
@@ -754,6 +752,6 @@
if t not in ignore and t[0] != '.':
if target != '':
params['target'] = join(target,t+ext)
- make_meta_file(i, url, params, progress = vc)
+ make_meta_file(i, params, progress = vc)
except ValueError:
print_exc()
Modified: debtorrent/branches/unique/DebTorrent/download_bt1.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/DebTorrent/download_bt1.py?rev=222&op=diff
==============================================================================
--- debtorrent/branches/unique/DebTorrent/download_bt1.py (original)
+++ debtorrent/branches/unique/DebTorrent/download_bt1.py Sun Aug 12 00:47:24 2007
@@ -150,10 +150,10 @@
('disable_http_downloader', 0,
'(for testing purposes only) whether to disable the backup HTTP downloader'),
# Other Things
- ('separate_all',0, 'whether to separate the architecture:all packages, ' +
+ ('separate_all', 3, 'whether to separate the architecture:all packages, ' +
'0 = don\'t separate, 1 = separate and run architecture:all, ' +
'2 = separate and run all architectures but all, ' +
- '3 = separate and run both (not for btdownloadheadless)'),
+ '3 = separate and run both'),
# End of Normal Options
# BitTorrent Options
('keepalive_interval', 120.0,
@@ -429,8 +429,19 @@
return (None, None)
sub_pieces = getsubpieces(name)
-
- (info, info_all) = getpieces(h, separate_all = separate_all, sub_pieces = sub_pieces)
+
+ (piece_ordering, ordering_headers) = getordering(name)
+ if separate_all:
+ (piece_ordering_all, ordering_all_headers) = getordering(name, all = True)
+ else:
+ piece_ordering_all = {}
+ ordering_all_headers = {}
+
+ (info, info_all) = getpieces(h, separate_all = separate_all, sub_pieces = sub_pieces,
+ piece_ordering = piece_ordering,
+ piece_ordering_all = piece_ordering_all,
+ num_pieces = int(ordering_headers.get('NextPiece', 0)),
+ num_all_pieces = int(ordering_all_headers.get('NextPiece', 0)))
response = None
response_all = None
@@ -439,11 +450,29 @@
'announce': default_tracker,
'name': uniconvert(name)}
+ if "Tracker" in ordering_headers:
+ response['announce'] = ordering_headers["Tracker"].strip()
+ del ordering_headers["Tracker"]
+ if "Torrent" in ordering_headers:
+ response['identifier'] = binascii.a2b_hex(ordering_headers["Torrent"].strip())
+ del ordering_headers["Torrent"]
+ for header, value in ordering_headers.items():
+ response[header] = value.strip()
+
if info_all:
response_all = {'info': info_all,
'announce': default_tracker,
'name': uniconvert(convert_all(name))}
+ if "Tracker" in ordering_all_headers:
+ response_all['announce'] = ordering_all_headers["Tracker"].strip()
+ del ordering_all_headers["Tracker"]
+ if "Torrent" in ordering_all_headers:
+ response_all['identifier'] = binascii.a2b_hex(ordering_all_headers["Torrent"].strip())
+ del ordering_all_headers["Torrent"]
+ for header, value in ordering_all_headers.items():
+ response_all[header] = value.strip()
+
except IOError, e:
logger.exception('problem getting Packages info')
return (None, None)
Modified: debtorrent/branches/unique/DebTorrent/launchmanycore.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/DebTorrent/launchmanycore.py?rev=222&op=diff
==============================================================================
--- debtorrent/branches/unique/DebTorrent/launchmanycore.py (original)
+++ debtorrent/branches/unique/DebTorrent/launchmanycore.py Sun Aug 12 00:47:24 2007
@@ -637,7 +637,7 @@
file_num += 1
# Check that the file ends with the desired file name
- if file.endswith('/'.join(f['path'])):
+ if f['path'] and file.endswith('/'.join(f['path'])):
logger.debug('Found file in: '+str(binascii.b2a_hex(hash)))
found_torrents.append((hash, file_num))
Modified: debtorrent/branches/unique/btcompletedir.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/btcompletedir.py?rev=222&op=diff
==============================================================================
--- debtorrent/branches/unique/btcompletedir.py (original)
+++ debtorrent/branches/unique/btcompletedir.py Sun Aug 12 00:47:24 2007
@@ -48,9 +48,9 @@
print "\nProcessing file: %s" % file
-if len(argv) < 3:
+if len(argv) < 2:
a,b = split(argv[0])
- print 'Usage: ' + b + ' <trackerurl> <dir> [dir...] [params...]'
+ print 'Usage: ' + b + ' <dir> [dir...] [params...]'
print 'makes a .dtorrent file for every Packages file present in each dir.'
print
print formatDefinitions(defaults, 80)
@@ -59,9 +59,9 @@
exit(2)
try:
- config, args = parseargs(argv[1:], defaults, 2, None)
- for dir in args[1:]:
- completedir(dir, args[0], config, vc = prog, fc = next_file)
+ config, args = parseargs(argv[1:], defaults, 1, None)
+ for dir in args:
+ completedir(dir, config, vc = prog, fc = next_file)
except ValueError, e:
print 'error: ' + str(e)
print 'run with no args for parameter explanations'
Modified: debtorrent/branches/unique/btmakemetafile.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/btmakemetafile.py?rev=222&op=diff
==============================================================================
--- debtorrent/branches/unique/btmakemetafile.py (original)
+++ debtorrent/branches/unique/btmakemetafile.py Sun Aug 12 00:47:24 2007
@@ -52,7 +52,7 @@
try:
config, args = parseargs(argv[1:], defaults, 1, None)
- for file in args[0:]:
+ for file in args:
make_meta_file(file, config, progress = prog)
print ''
except ValueError, e:
Modified: debtorrent/branches/unique/test.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/unique/test.py?rev=222&op=diff
==============================================================================
--- debtorrent/branches/unique/test.py (original)
+++ debtorrent/branches/unique/test.py Sun Aug 12 00:47:24 2007
@@ -468,7 +468,7 @@
# Create apt's config files
f = open(join([downloader_dir, 'etc', 'apt', 'sources.list']), 'w')
- f.write('deb http://localhost:' + str(num_down) + '988/' + mirror + '/ stable ' + suites + '\n')
+ f.write('deb http://localhost:' + str(num_down) + '988/' + mirror + '/ unstable ' + suites + '\n')
f.close()
f = open(join([downloader_dir, 'etc', 'apt', 'apt.conf']), 'w')
More information about the Debtorrent-commits
mailing list