Only report progress if connected to a TTY
This commit is contained in:
parent
581a373dae
commit
43c04df98a
13
publish.py
13
publish.py
@ -177,7 +177,6 @@ class ReadFileWithProgressReporting(io.FileIO): # {{{
|
|||||||
def write(*args: str) -> None:
|
def write(*args: str) -> None:
|
||||||
print(*args, end='')
|
print(*args, end='')
|
||||||
|
|
||||||
write('\x1b[s\x1b[K')
|
|
||||||
frac = float(self.tell()) / self._total
|
frac = float(self.tell()) / self._total
|
||||||
mb_pos = self.tell() / float(1024**2)
|
mb_pos = self.tell() / float(1024**2)
|
||||||
mb_tot = self._total / float(1024**2)
|
mb_tot = self._total / float(1024**2)
|
||||||
@ -186,14 +185,12 @@ class ReadFileWithProgressReporting(io.FileIO): # {{{
|
|||||||
bit_rate = kb_rate * 1024
|
bit_rate = kb_rate * 1024
|
||||||
eta = int((self._total - self.tell()) / bit_rate) + 1
|
eta = int((self._total - self.tell()) / bit_rate) + 1
|
||||||
eta_m, eta_s = eta / 60, eta % 60
|
eta_m, eta_s = eta / 60, eta % 60
|
||||||
write(
|
if sys.stdout.isatty():
|
||||||
' %.1f%% %.1f/%.1fMB %.1f KB/sec %d minutes, %d seconds left'
|
write(
|
||||||
% (frac * 100, mb_pos, mb_tot, kb_rate, eta_m, eta_s))
|
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')
|
||||||
write('\x1b[u')
|
|
||||||
if self.tell() >= self._total:
|
if self.tell() >= self._total:
|
||||||
t = int(time.time() - self.start_time) + 1
|
t = int(time.monotonic() - self.start_time) + 1
|
||||||
print('\nUpload took %d minutes and %d seconds at %.1f KB/sec' %
|
print(f'\nUpload took {t/60} minutes and {t%60} seconds at {kb_rate:.1f} KB/sec')
|
||||||
(t / 60, t % 60, kb_rate))
|
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user