From fd552842d441e12896d2ddc617fe22da3b9d541e Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 17 Feb 2024 23:19:11 +0000 Subject: [PATCH] fix other possible division-by-zeros; u2c: also fix exe detection --- bin/u2c.py | 14 +++++++------- copyparty/authsrv.py | 2 +- copyparty/up2k.py | 2 +- copyparty/util.py | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/bin/u2c.py b/bin/u2c.py index 4054532b..7076b17a 100755 --- a/bin/u2c.py +++ b/bin/u2c.py @@ -1,8 +1,8 @@ #!/usr/bin/env python3 from __future__ import print_function, unicode_literals -S_VERSION = "1.14" -S_BUILD_DT = "2024-01-27" +S_VERSION = "1.15" +S_BUILD_DT = "2024-02-18" """ u2c.py: upload to copyparty @@ -29,7 +29,7 @@ import platform import threading import datetime -EXE = sys.executable.endswith("exe") +EXE = bool(getattr(sys, "frozen", False)) try: import argparse @@ -846,12 +846,12 @@ class Ctl(object): txt = " " if not self.up_br: - spd = self.hash_b / (time.time() - self.t0) - eta = (self.nbytes - self.hash_b) / (spd + 1) + spd = self.hash_b / ((time.time() - self.t0) or 1) + eta = (self.nbytes - self.hash_b) / (spd or 1) else: - spd = self.up_br / (time.time() - self.t0_up) + spd = self.up_br / ((time.time() - self.t0_up) or 1) spd = self.spd = (self.spd or spd) * 0.9 + spd * 0.1 - eta = (self.nbytes - self.up_b) / (spd + 1) + eta = (self.nbytes - self.up_b) / (spd or 1) spd = humansize(spd) self.eta = str(datetime.timedelta(seconds=int(eta))) diff --git a/copyparty/authsrv.py b/copyparty/authsrv.py index cbb1d662..df945b63 100644 --- a/copyparty/authsrv.py +++ b/copyparty/authsrv.py @@ -193,7 +193,7 @@ class Lim(object): self.dft = int(time.time()) + 300 self.dfv = get_df(abspath)[0] or 0 for j in list(self.reg.values()) if self.reg else []: - self.dfv -= int(j["size"] / len(j["hash"]) * len(j["need"])) + self.dfv -= int(j["size"] / (len(j["hash"]) or 999) * len(j["need"])) if already_written: sz = 0 diff --git a/copyparty/up2k.py b/copyparty/up2k.py index c86f0417..430d6c93 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -552,7 +552,7 @@ class Up2k(object): runihook(self.log, cmd, vol, ups) def _vis_job_progress(self, job: dict[str, Any]) -> str: - perc = 100 - (len(job["need"]) * 100.0 / len(job["hash"])) + perc = 100 - (len(job["need"]) * 100.0 / (len(job["hash"]) or 1)) path = djoin(job["ptop"], job["prel"], job["name"]) return "{:5.1f}% {}".format(perc, path) diff --git a/copyparty/util.py b/copyparty/util.py index e3b7c6b1..3be6c9c3 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -1768,7 +1768,7 @@ def get_spd(nbyte: int, t0: float, t: Optional[float] = None) -> str: if t is None: t = time.time() - bps = nbyte / ((t - t0) + 0.001) + bps = nbyte / ((t - t0) or 0.001) s1 = humansize(nbyte).replace(" ", "\033[33m").replace("iB", "") s2 = humansize(bps).replace(" ", "\033[35m").replace("iB", "") return "%s \033[0m%s/s\033[0m" % (s1, s2)