示例#1
0
 def test_human_size(self):
     cases = [
         (0, "   0 bytes"),
         ("123", " 123 bytes"),
         (123, " 123 bytes"),
         (-1, "-??? bytes"),
         (1023, "1023 bytes"),
         (1024**1, "   1.0 KiB"),
         (1024**2, "   1.0 MiB"),
         (1024**3, "   1.0 GiB"),
         (1024**4, "1024.0 GiB"),
         (1024**2 - 51, "1024.0 KiB"),
         (1024**2 - 52, "1023.9 KiB"),
         (1024**2 - 512, "1023.5 KiB"),
         #(, ""),
     ]
     for val, expected in cases:
         result = fmt.human_size(val)
         assert result == expected
示例#2
0
 def test_human_size(self):
     cases = [
         (0,         "   0 bytes"),
         ("123",     " 123 bytes"),
         (123,       " 123 bytes"),
         (-1,        "-??? bytes"),
         (1023,      "1023 bytes"),
         (1024**1,   "   1.0 KiB"),
         (1024**2,   "   1.0 MiB"),
         (1024**3,   "   1.0 GiB"),
         (1024**4,   "1024.0 GiB"),
         (1024**2-51,    "1024.0 KiB"),
         (1024**2-52,    "1023.9 KiB"),
         (1024**2-512,   "1023.5 KiB"),
         #(, ""),
     ]
     for val, expected in cases:
         result = fmt.human_size(val)
         assert result == expected
示例#3
0
    def mainloop(self):
        proxy = config.engine.open()
        all_items = list(config.engine.multicall("incomplete", self.FIELDS))

        pending = [d for d in all_items if not d.is_active and d.priority > 0]
        print(
            "Queued items:          ",
            fmt.human_size(sum(d.size_bytes for d in pending)), 'in',
            len(pending), 'item(s)', '[{} free]'.format(
                fmt.human_size(disk_free(proxy.directory.default())).strip()))

        items = [d for d in all_items if d.is_active]
        if not items:
            print("No active downloads!")
            return

        good_rates = [
            d.down_rate for d in items if d.down_rate > self.MIN_STALLED_RATE
        ]
        stalled_rate = max(
            self.MIN_STALLED_RATE, self.STALLED_PERCENT / 100 *
            sum(good_rates) / len(good_rates) if good_rates else 0)
        stalled_count = sum(d.down_rate < stalled_rate for d in items)
        global_down_rate = proxy.throttle.global_down.rate()

        total_size = sum(d.size_bytes for d in items)
        total_left = sum(d.left_bytes for d in items)
        eta_list = [0]
        if stalled_count < len(items):
            eta_list = [
                d.left_bytes / d.down_rate for d in items
                if d.down_rate >= stalled_rate
            ]

        stalled_info = ', {} stalled below {}/s'.format(
            stalled_count,
            fmt.human_size(stalled_rate).strip()) if stalled_count else ''
        print("Size left to download: ", fmt.human_size(total_left), 'of',
              fmt.human_size(total_size).strip())
        print("Overall download speed:",
              fmt.human_size(global_down_rate) + '/s')
        print(
            "ETA (min / max):       ",
            fmt_duration(min(eta_list)),
            '…',
            fmt_duration(max(eta_list)),
            '[{} item(s){}]'.format(len(items), stalled_info),
        )
示例#4
0
def test_fmt_human_size(val, expected):
    result = fmt.human_size(val)
    assert result == expected
示例#5
0
文件: mktor.py 项目: r4b3rt/pyrocore
 def human(size):
     'Helper for byte sizes'
     text = fmt.human_size(size)
     return text[:4].lstrip() + ('' if size < 1024 else text[-3])