[Debtorrent-commits] r33 - in /debtorrent/trunk: DebTorrent/download_bt1.py README.txt TODO

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Thu May 3 07:30:04 UTC 2007


Author: camrdale-guest
Date: Thu May  3 07:30:03 2007
New Revision: 33

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=33
Log:
Make the downloaders work directly on Packages files and URLs

Modified:
    debtorrent/trunk/DebTorrent/download_bt1.py
    debtorrent/trunk/README.txt
    debtorrent/trunk/TODO

Modified: debtorrent/trunk/DebTorrent/download_bt1.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/DebTorrent/download_bt1.py?rev=33&op=diff
==============================================================================
--- debtorrent/trunk/DebTorrent/download_bt1.py (original)
+++ debtorrent/trunk/DebTorrent/download_bt1.py Thu May  3 07:30:03 2007
@@ -33,6 +33,17 @@
 from clock import clock
 from BTcrypto import CRYPTO_OK
 from __init__ import createPeerID
+from BT1.makemetafile import uniconvertl, uniconvert
+from os.path import split
+from gzip import GzipFile
+from StringIO import StringIO
+import binascii
+try:
+    from sys import getfilesystemencoding
+    ENCODING = getfilesystemencoding()
+except:
+    from sys import getdefaultencoding
+    ENCODING = getdefaultencoding()
 
 try:
     True
@@ -270,6 +281,14 @@
 
 
 def get_response(file, url, errorfunc):
+    response = get_packages(file, url, errorfunc)
+    if response:
+        try:
+            check_message(response)
+        except ValueError, e:
+            errorfunc("got bad file info - " + str(e))
+            return None
+        return response
     try:
         if file:
             h = open(file, 'rb')
@@ -318,8 +337,17 @@
     return response
 
 def get_packages(file, url, errorfunc):
+    encoding = None
+#    if params.has_key('filesystem_encoding'):
+#        encoding = params['filesystem_encoding']
+    if not encoding:
+        encoding = ENCODING
+    if not encoding:
+        encoding = 'ascii'
+
     try:
         if file:
+            name = split(file)[1]
             h = open(file, 'r')
             try:
                 for line in h:   # quick test to see if packages file is correct
@@ -327,7 +355,7 @@
                         break
                 assert line[:8] == "Package:"
             except:
-                errorfunc(file+' is not a valid Packages file')
+#                errorfunc(file+' is not a valid Packages file')
                 return None
             try:
                 h.seek(0)
@@ -338,17 +366,25 @@
                     pass
                 h = open(file, 'r')
         else:
+            urlp = urlparse(url)
+            name = urlp[1] + urlp[2].replace('/','_')
             try:
                 h = urlopen(url)
                 file = url
+                data = h.read()
+                if url[-3:] == ".gz":
+                    compressed = StringIO(data)
+                    f = GzipFile(fileobj = compressed)
+                    data = f.read()
+                    name = urlp[1] + urlp[2][:-3].replace('/','_')
+                h = data.split('\n')
             except:
-                errorfunc(url+' bad url')
+#                errorfunc(url+' bad url')
                 return None
 
         pieces = []
         lengths = []
         fs = []
-        packages = 0
         
         p = [None, None, None]
         for line in h:
@@ -362,8 +398,6 @@
                     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:]
@@ -375,20 +409,15 @@
         response = {'info': {'pieces': ''.join(pieces),
             'piece lengths': lengths, 'files': fs },
             'announce': 'http://dttracker.debian.net:6969/announce', 
-            'name': uniconvert(split(file)[1], encoding) }
+            'name': uniconvert(name, encoding) }
     
     except IOError, e:
-        errorfunc('problem getting Packages info - ' + str(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
 

Modified: debtorrent/trunk/README.txt
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/README.txt?rev=33&op=diff
==============================================================================
--- debtorrent/trunk/README.txt (original)
+++ debtorrent/trunk/README.txt Thu May  3 07:30:03 2007
@@ -8,9 +8,9 @@
 
    cd debtorrent
 
-3. Get a .dtorrent file:
+3. Choose an archive to download:
 
-   a) Choose one from the dtorrents directory
+   a) Choose a .dtorrent file from the dtorrents directory
    
       You can view the contents of the file using the btshowmetainfo.py command
       
@@ -20,18 +20,30 @@
          
       and look for the info hash shown by btshowmetainfo.
 
-   b) Or, create one using btmakemetafile from a Packages file:
+   b) Or, create a .dtorrent file using btmakemetafile from a Packages file:
 
       btmakemetafile.py http://dttracker.debian.net:6969/announce \
           /var/lib/apt/lists/<mirror>_debian_dists_<suite>_<section>_binary-<arch>_Packages \
           --target test.dtorrent
 
-      The recommended Packages file to use is from the stable suite (as it 
-      doesn't change much), and section contrib (as it's the smallest).
+   c) Or, choose a Packages file from /var/lib/apt/lists/
+   
+   d) Or, find one on the web, for example:
+   
+      http://ftp.us.debian.org/debian/dists/stable/contrib/binary-i386/Packages.gz
+      
+   The recommended Packages file to use is from the stable suite (as it 
+   doesn't change much), and section contrib (as it's the smallest).
 
-4. Start the download:
+4. Start the download, depending on step 3, do the following:
 
-   btdownloadheadless.py test.dtorrent
+   a) btdownloadheadless.py dtorrents/<file>.dtorrent
+
+   b) btdownloadheadless.py test.dtorrent
+
+   c) btdownloadheadless.py /var/lib/apt/lists/<mirror>_debian_dists_<suite>_<section>_binary-<arch>_Packages
+
+   d) btdownloadheadless.py http://ftp.us.debian.org/debian/dists/stable/contrib/binary-i386/Packages.gz
 
    You can use some of the options to btdownloadheadless (to see them, run it
    without arguments) but most are untested, and some will break the download
@@ -45,3 +57,16 @@
 to check if your torrent is active. If it is, but you still can't download,
 or if you get errors from running any of the programs, please post the
 problem/error to debtorrent-devel at lists.alioth.debian.org
+
+
+Known Bugs
+----------
+
+On starting a download, the following error is generated:
+
+Traceback (most recent call last):
+  File "/home/user/workspace/debtorrent/DebTorrent/inifile.py", line 113, in ini_read
+    r = open(f,'r')
+IOError: [Errno 2] No such file or directory: '/home/user/.DebTorrent/config.downloadheadless.ini'
+
+The error has no effect on the download.

Modified: debtorrent/trunk/TODO
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/trunk/TODO?rev=33&op=diff
==============================================================================
--- debtorrent/trunk/TODO (original)
+++ debtorrent/trunk/TODO Thu May  3 07:30:03 2007
@@ -1,4 +1,11 @@
 Below are some things that still need to be done, in order of priority.
+
+
+Make the URL download better
+
+The URL download is currently a little hacky, and could be improved. The 
+urlopen class could be made into an iterator, and could decompress files with 
+the ".gz" extension itself.
 
 
 Move the data cache from ~/.DebTorrent




More information about the Debtorrent-commits mailing list