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 / fmt.pyc (.txt) < prev    next >
Encoding:
Python Compiled Bytecode  |  2006-08-31  |  1.3 KB  |  61 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.4)
  3.  
  4.  
  5. def fmttime(n, compact = 0):
  6.     if n == -1:
  7.         if compact:
  8.             return '(no seeds?)'
  9.         else:
  10.             return 'download not progressing (no seeds?)'
  11.     
  12.     if n == 0:
  13.         if compact:
  14.             return 'complete'
  15.         else:
  16.             return 'download complete!'
  17.     
  18.     n = int(n)
  19.     (m, s) = divmod(n, 60)
  20.     (h, m) = divmod(m, 60)
  21.     if h > 1000000:
  22.         return 'n/a'
  23.     
  24.     if compact:
  25.         return '%d:%02d:%02d' % (h, m, s)
  26.     else:
  27.         return 'finishing in %d:%02d:%02d' % (h, m, s)
  28.  
  29.  
  30. def fmtsize(n, baseunit = 0, padded = 1):
  31.     unit = [
  32.         ' B',
  33.         ' K',
  34.         ' M',
  35.         ' G',
  36.         ' T',
  37.         ' P',
  38.         ' E',
  39.         ' Z',
  40.         ' Y']
  41.     i = baseunit
  42.     while i + 1 < len(unit) and n >= 999:
  43.         i += 1
  44.         n = float(n) / (1 << 10)
  45.     size = ''
  46.     if padded:
  47.         if n < 10:
  48.             size = '  '
  49.         elif n < 100:
  50.             size = ' '
  51.         
  52.     
  53.     if i != 0:
  54.         size += '%.1f %s' % (n, unit[i])
  55.     elif padded:
  56.         size += '%.0f   %s' % (n, unit[i])
  57.     else:
  58.         size += '%.0f %s' % (n, unit[i])
  59.     return size
  60.  
  61.