[Debtorrent-commits] r89 - in /debtorrent/branches/hippy: DebTorrent/BT1/makemetafile.py btmakemetafile.py

camrdale-guest at users.alioth.debian.org camrdale-guest at users.alioth.debian.org
Mon Jun 4 23:30:19 UTC 2007


Author: camrdale-guest
Date: Mon Jun  4 23:30:19 2007
New Revision: 89

URL: http://svn.debian.org/wsvn/debtorrent/?sc=1&rev=89
Log:
Add option to btmakemetafile to use another file for sub-package pieces.

Modified:
    debtorrent/branches/hippy/DebTorrent/BT1/makemetafile.py
    debtorrent/branches/hippy/btmakemetafile.py

Modified: debtorrent/branches/hippy/DebTorrent/BT1/makemetafile.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/hippy/DebTorrent/BT1/makemetafile.py?rev=89&op=diff
==============================================================================
--- debtorrent/branches/hippy/DebTorrent/BT1/makemetafile.py (original)
+++ debtorrent/branches/hippy/DebTorrent/BT1/makemetafile.py Mon Jun  4 23:30:19 2007
@@ -36,7 +36,8 @@
         "optional specification for filesystem encoding " +
         "(set automatically in recent Python versions)"),
     ('target', '',
-        "optional target file for the torrent")
+        "optional target file for the torrent"),
+    ('pieces_file', '', 'the file that contains the sub-package piece information'),
     ]
 
 default_piece_len_exp = 18
@@ -118,8 +119,13 @@
         encoding = ENCODING
     if not encoding:
         encoding = 'ascii'
-    
-    info = makeinfo(file, piece_length, encoding, flag, progress, progress_percent)
+
+    if params.has_key('pieces_file') and params['pieces_file']:
+        (sub_pieces, sub_piece_lengths) = getsubpieces(params['pieces_file'])
+        
+    info = makeinfo(file, piece_length, encoding, flag, progress, progress_percent,
+                    sub_pieces, sub_piece_lengths)
+    
     if flag.isSet():
         return
     check_info(info)
@@ -155,7 +161,39 @@
         total += getsize(s[1])
     return total
 
-def makeinfo(file, piece_length, encoding, flag, progress, progress_percent=1):
+def getsubpieces(file):
+    file = abspath(file)
+    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]
+                packages += 1
+                #progress(packages)
+            p = [None, [], []]
+            read_data = False
+        if read_data == True and line[:1] != " ":
+            read_data = False
+        if line[:9] == "Filename:":
+            p[0] = line[10:]
+        if line == "SHA1-Pieces:":
+            read_data = True
+        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)
+
+def makeinfo(file, piece_length, encoding, flag, progress, progress_percent=1,
+             sub_pieces = {}, sub_piece_lengths = {}):
     file = abspath(file)
     pieces = []
     lengths = []
@@ -168,13 +206,18 @@
         line = line.rstrip()
         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]])
+                else:
+                    lengths.append(p[0])
+                    pieces.append(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]

Modified: debtorrent/branches/hippy/btmakemetafile.py
URL: http://svn.debian.org/wsvn/debtorrent/debtorrent/branches/hippy/btmakemetafile.py?rev=89&op=diff
==============================================================================
--- debtorrent/branches/hippy/btmakemetafile.py (original)
+++ debtorrent/branches/hippy/btmakemetafile.py Mon Jun  4 23:30:19 2007
@@ -54,6 +54,7 @@
     config, args = parseargs(argv[1:], defaults, 2, None)
     for file in args[1:]:
         make_meta_file(file, args[0], config, progress = prog)
+        print ''
 except ValueError, e:
     print 'error: ' + str(e)
     print 'run with no args for parameter explanations'




More information about the Debtorrent-commits mailing list