home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2007 September / PCWSEP07.iso / Software / Linux / Linux Mint 3.0 Light / LinuxMint-3.0-Light.iso / casper / filesystem.squashfs / usr / bin / btcompletedir.bittorrent < prev    next >
Encoding:
Text File  |  2007-02-19  |  1.1 KB  |  47 lines

  1. #! /usr/bin/python
  2.  
  3. # Written by Bram Cohen
  4. # see LICENSE.txt for license information
  5.  
  6. from os.path import join, split
  7. from threading import Event
  8. from traceback import print_exc
  9. from sys import argv
  10. from BitTorrent.btmakemetafile import calcsize, make_meta_file, ignore
  11.  
  12. def dummy(x):
  13.     pass
  14.  
  15. def completedir(files, url, flag = Event(), vc = dummy, fc = dummy, piece_len_pow2 = None):
  16.     files.sort()
  17.     ext = '.torrent'
  18.  
  19.     togen = []
  20.     for f in files:
  21.         if f[-len(ext):] != ext:
  22.             togen.append(f)
  23.         
  24.     total = 0
  25.     for i in togen:
  26.         total += calcsize(i)
  27.  
  28.     subtotal = [0]
  29.     def callback(x, subtotal = subtotal, total = total, vc = vc):
  30.         subtotal[0] += x
  31.         vc(float(subtotal[0]) / total)
  32.     for i in togen:
  33.         t = split(i)
  34.         if t[1] == '':
  35.             i = t[0]
  36.         fc(i)
  37.         try:
  38.             make_meta_file(i, url, flag = flag, progress = callback, progress_percent=0, piece_len_exp = piece_len_pow2)
  39.         except ValueError:
  40.             print_exc()
  41.  
  42. def dc(v):
  43.     print v
  44.  
  45. if __name__ == '__main__':
  46.     completedir(argv[2:], argv[1], fc = dc)
  47.