[Debtorrent-commits] r19 -
/debtorrent/trunk/DebTorrent/download_bt1.py
camrdale-guest at users.alioth.debian.org
camrdale-guest at users.alioth.debian.org
Fri Apr 27 23:32:11 UTC 2007
Author: camrdale-guest
Date: Fri Apr 27 23:32:11 2007
New Revision: 19
URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=19
Log:
Initial work on using Packages files directly
Modified:
debtorrent/trunk/DebTorrent/download_bt1.py
Modified: debtorrent/trunk/DebTorrent/download_bt1.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/download_bt1.py?rev=19&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/download_bt1.py (original)
+++ debtorrent/trunk/DebTorrent/download_bt1.py Fri Apr 27 23:32:11 2007
@@ -316,6 +316,82 @@
return response
+# TODO: make this function work
+def get_packages(file, url, errorfunc):
+ try:
+ if file:
+ h = open(file, 'r')
+ try:
+ for line in h: # quick test to see if packages file is correct
+ if len(line.strip()) > 0:
+ break
+ assert line[:8] == "Package:"
+ except:
+ errorfunc(file+' is not a valid Packages file')
+ return None
+ try:
+ h.seek(0)
+ except:
+ try:
+ h.close()
+ except:
+ pass
+ h = open(file, 'r')
+ else:
+ try:
+ h = urlopen(url)
+ file = url
+ except:
+ errorfunc(url+' bad url')
+ return None
+
+ pieces = []
+ lengths = []
+ fs = []
+ packages = 0
+
+ p = [None, None, None]
+ for line in h:
+ line = line.rstrip()
+ if line == "":
+ if (p[0] and p[1] and p[2]):
+ path = []
+ while p[1]:
+ p[1],d = split(p[1])
+ path.insert(0,d)
+ fs.append({'length': p[0], 'path': uniconvertl(path, encoding)})
+ lengths.append(p[0])
+ pieces.append(p[2])
+ packages += 1
+ progress(packages)
+ p = [None, None, None]
+ if line[:9] == "Filename:":
+ p[1] = line[10:]
+ if line[:5] == "Size:":
+ p[0] = long(line[6:])
+ if line[:5] == "SHA1:":
+ p[2] = binascii.a2b_hex(line[6:])
+
+ response = {'info': {'pieces': ''.join(pieces),
+ 'piece lengths': lengths, 'files': fs,
+ 'name': uniconvert(split(file)[1], encoding) },
+ 'announce': 'http://dttracker.debian.net:6969/announce' }
+
+ except IOError, e:
+ errorfunc('problem getting Packages info - ' + str(e))
+ return None
+ try:
+ h.close()
+ except:
+ pass
+ try:
+ check_message(response)
+ except ValueError, e:
+ errorfunc("got bad file info - " + str(e))
+ return None
+
+ return response
+
class BT1Download:
def __init__(self, statusfunc, finfunc, errorfunc, excfunc, doneflag,
More information about the Debtorrent-commits
mailing list