| 231 | return data |
| 232 | |
| 233 | def report_progress(self, size: int) -> None: |
| 234 | def write(*args: str) -> None: |
| 235 | print(*args, end='') |
| 236 | |
| 237 | frac = int(self.tell() * 100 / self._total) |
| 238 | mb_pos = self.tell() / float(1024**2) |
| 239 | mb_tot = self._total / float(1024**2) |
| 240 | kb_pos = self.tell() / 1024.0 |
| 241 | kb_rate = kb_pos / (time.monotonic() - self.start_time) |
| 242 | bit_rate = kb_rate * 1024 |
| 243 | eta = int((self._total - self.tell()) / bit_rate) + 1 |
| 244 | eta_m, eta_s = divmod(eta, 60) |
| 245 | if sys.stdout.isatty(): |
| 246 | write( |
| 247 | f'\r\033[K\033[?7h {frac}% {mb_pos:.1f}/{mb_tot:.1f}MB {kb_rate:.1f} KB/sec {eta_m} minutes, {eta_s} seconds left\033[?7l') |
| 248 | if self.tell() >= self._total: |
| 249 | t = int(time.monotonic() - self.start_time) + 1 |
| 250 | print(f'\nUpload took {t//60} minutes and {t%60} seconds at {kb_rate:.1f} KB/sec') |
| 251 | sys.stdout.flush() |
| 252 | |
| 253 | |
| 254 | # }}} |