[Debtorrent-commits] r90 - /debtorrent/branches/hippy/DebTorrent/BT1/makemetafile.py
camrdale-guest at users.alioth.debian.org
camrdale-guest at users.alioth.debian.org
Tue Jun 5 00:31:03 UTC 2007
Author: camrdale-guest
Date: Tue Jun 5 00:31:03 2007
New Revision: 90
URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=90
Log:
Make btmakemetafile check merkel.d.o for extrapieces files. (Warning, release names hardcoded.)
Modified:
debtorrent/branches/hippy/DebTorrent/BT1/makemetafile.py
Modified: debtorrent/branches/hippy/DebTorrent/BT1/makemetafile.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/hippy/DebTorrent/BT1/makemetafile.py?rev=90&op=diff
==============================================================================
--- debtorrent/branches/hippy/DebTorrent/BT1/makemetafile.py (original)
+++ debtorrent/branches/hippy/DebTorrent/BT1/makemetafile.py Tue Jun 5 00:31:03 2007
@@ -15,6 +15,9 @@
from threading import Event
from time import time
from traceback import print_exc
+from DebTorrent.zurllib import urlopen
+from gzip import GzipFile
+from StringIO import StringIO
import binascii
try:
from sys import getfilesystemencoding
@@ -120,11 +123,56 @@
if not encoding:
encoding = 'ascii'
+ sub_pieces = {}
if params.has_key('pieces_file') and params['pieces_file']:
- (sub_pieces, sub_piece_lengths) = getsubpieces(params['pieces_file'])
+ try:
+ h = open(params['pieces_file'])
+ sub_pieces = getsubpieces(h)
+ except:
+ print 'The specified pieces file could not be read, it will be ignored'
+ sub_pieces = {}
+ try:
+ h.close()
+ except:
+ pass
+ elif 'dists' in file.split('_'):
+ try:
+ parts = file.split('_')
+ try:
+ parts[parts.index('stable', parts.index('dists'))] = 'etch'
+ except:
+ pass
+ try:
+ parts[parts.index('testing', parts.index('dists'))] = 'lenny'
+ except:
+ pass
+ try:
+ parts[parts.index('unstable', parts.index('dists'))] = 'sid'
+ except:
+ pass
+ piece_url = 'http://merkel.debian.org/~ajt/extrapieces/dists_'
+ piece_url += '_'.join(parts[parts.index('dists')+1:])
+ piece_url += '-extrapieces.gz'
+ piece_file = urlopen(piece_url)
+ piece_data = piece_file.read()
+ try:
+ piece_file.close()
+ except:
+ pass
+ if url[-3:] == ".gz":
+ compressed = StringIO(piece_data)
+ piece_file = GzipFile(fileobj = compressed)
+ piece_data = piece_file.read()
+ h = piece_data.split('\n')
+ sub_pieces = getsubpieces(h)
+ except:
+ sub_pieces = {}
+
+ if not sub_pieces:
+ print 'WARNING: Pieces file could not be found, not using sub-package pieces.'
info = makeinfo(file, piece_length, encoding, flag, progress, progress_percent,
- sub_pieces, sub_piece_lengths)
+ sub_pieces)
if flag.isSet():
return
@@ -161,21 +209,17 @@
total += getsize(s[1])
return total
-def getsubpieces(file):
- file = abspath(file)
+def getsubpieces(f):
pieces = {}
- lengths = {}
packages = 0
p = [None, [], []]
read_data = False
- f = open(file)
for line in f:
line = line.rstrip()
if line == "":
if (p[0] and p[1] and p[2]):
- pieces[p[0]] = p[1]
- lengths[p[0]] = p[2]
+ pieces[p[0]] = (p[1], p[2])
packages += 1
#progress(packages)
p = [None, [], []]
@@ -189,11 +233,10 @@
if read_data == True and line[:1] == " ":
p[1].append(binascii.a2b_hex(line[1:41]))
p[2].append(int(line[42:]))
- f.close()
- return (pieces, lengths)
+ return pieces
def makeinfo(file, piece_length, encoding, flag, progress, progress_percent=1,
- sub_pieces = {}, sub_piece_lengths = {}):
+ sub_pieces = {}):
file = abspath(file)
pieces = []
lengths = []
@@ -207,8 +250,8 @@
if line == "":
if (p[0] and p[1] and p[2]):
if sub_pieces.has_key(p[1]):
- lengths.extend(sub_piece_lengths[p[1]])
- pieces.extend(sub_pieces[p[1]])
+ lengths.extend(sub_pieces[p[1]][1])
+ pieces.extend(sub_pieces[p[1]][0])
else:
lengths.append(p[0])
pieces.append(p[2])
More information about the Debtorrent-commits
mailing list