home *** CD-ROM | disk | FTP | other *** search
/ PC Welt 2006 November (DVD) / PCWELT_11_2006.ISO / casper / filesystem.squashfs / usr / lib / python2.4 / site-packages / BitTorrent / btcompletedir.pyo (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  1.8 KB  |  58 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.4)
  3.  
  4. from os.path import join, split
  5. from threading import Event
  6. from traceback import print_exc
  7. from sys import argv
  8. from BitTorrent.btmakemetafile import calcsize, make_meta_file, ignore
  9.  
  10. def dummy(x):
  11.     pass
  12.  
  13.  
  14. def completedir(files, url, flag = Event(), vc = dummy, fc = dummy, piece_len_pow2 = None):
  15.     files.sort()
  16.     ext = '.torrent'
  17.     togen = []
  18.     for f in files:
  19.         if f[-len(ext):] != ext:
  20.             togen.append(f)
  21.             continue
  22.     
  23.     total = 0
  24.     for i in togen:
  25.         total += calcsize(i)
  26.     
  27.     subtotal = [
  28.         0]
  29.     
  30.     def callback(x, subtotal = subtotal, total = total, vc = vc):
  31.         subtotal[0] += x
  32.         vc(float(subtotal[0]) / total)
  33.  
  34.     for i in togen:
  35.         t = split(i)
  36.         if t[1] == '':
  37.             i = t[0]
  38.         
  39.         fc(i)
  40.         
  41.         try:
  42.             make_meta_file(i, url, flag = flag, progress = callback, progress_percent = 0, piece_len_exp = piece_len_pow2)
  43.         continue
  44.         except ValueError:
  45.             print_exc()
  46.             continue
  47.         
  48.  
  49.     
  50.  
  51.  
  52. def dc(v):
  53.     print v
  54.  
  55. if __name__ == '__main__':
  56.     completedir(argv[2:], argv[1], fc = dc)
  57.  
  58.