From 86419b8f477ab24178ab2d92e41e2b1a0cecec5d Mon Sep 17 00:00:00 2001 From: ed Date: Wed, 10 Jan 2024 23:20:42 +0100 Subject: [PATCH] suboptimizations and some future safeguards --- bin/u2c.py | 7 +++---- copyparty/__main__.py | 2 +- copyparty/broker_mpw.py | 2 +- copyparty/httpcli.py | 21 +++++++++++---------- copyparty/httpconn.py | 4 ++-- copyparty/httpsrv.py | 8 +++----- copyparty/ico.py | 10 +++++----- copyparty/mtag.py | 2 +- copyparty/star.py | 12 ++++++------ copyparty/svchub.py | 6 +++--- copyparty/th_srv.py | 6 +++--- copyparty/up2k.py | 34 +++++++++++++++++----------------- copyparty/util.py | 40 ++++++++++++++++++++-------------------- scripts/sfx.py | 6 +++--- 14 files changed, 79 insertions(+), 81 deletions(-) diff --git a/bin/u2c.py b/bin/u2c.py index 990bcf73..de074f91 100755 --- a/bin/u2c.py +++ b/bin/u2c.py @@ -1057,14 +1057,13 @@ class Ctl(object): self.uploader_busy += 1 self.t0_up = self.t0_up or time.time() - zs = "{0}/{1}/{2}/{3} {4}/{5} {6}" - stats = zs.format( + stats = "%d/%d/%d/%d %d/%d %s" % ( self.up_f, len(self.recheck), self.uploader_busy, self.nfiles - self.up_f, - int(self.nbytes / (1024 * 1024)), - int((self.nbytes - self.up_b) / (1024 * 1024)), + self.nbytes // (1024 * 1024), + (self.nbytes - self.up_b) // (1024 * 1024), self.eta, ) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 816a1f07..d999134f 100755 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -1432,7 +1432,7 @@ def main(argv: Optional[list[str]] = None) -> None: _, hard = resource.getrlimit(resource.RLIMIT_NOFILE) if hard > 0: # -1 == infinite - nc = min(nc, hard // 4) + nc = min(nc, int(hard / 4)) except: nc = 512 diff --git a/copyparty/broker_mpw.py b/copyparty/broker_mpw.py index 1a899e87..e74c4547 100644 --- a/copyparty/broker_mpw.py +++ b/copyparty/broker_mpw.py @@ -76,7 +76,7 @@ class MpWorker(BrokerCli): pass def logw(self, msg: str, c: Union[int, str] = 0) -> None: - self.log("mp{}".format(self.n), msg, c) + self.log("mp%d" % (self.n,), msg, c) def main(self) -> None: while True: diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 816ac69b..8c27a556 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -190,7 +190,7 @@ class HttpCli(object): def unpwd(self, m: Match[str]) -> str: a, b, c = m.groups() - return "{}\033[7m {} \033[27m{}".format(a, self.asrv.iacct[b], c) + return "%s\033[7m %s \033[27m%s" % (a, self.asrv.iacct[b], c) def _check_nonfatal(self, ex: Pebkac, post: bool) -> bool: if post: @@ -557,16 +557,16 @@ class HttpCli(object): self.keepalive = False em = str(ex) - msg = em if pex == ex else min_ex() + msg = em if pex is ex else min_ex() if pex.code != 404 or self.do_log: self.log( - "{}\033[0m, {}".format(msg, self.vpath), + "%s\033[0m, %s" % (msg, self.vpath), 6 if em.startswith("client d/c ") else 3, ) - msg = "{}\r\nURL: {}\r\n".format(em, self.vpath) + msg = "%s\r\nURL: %s\r\n" % (em, self.vpath) if self.hint: - msg += "hint: {}\r\n".format(self.hint) + msg += "hint: %s\r\n" % (self.hint,) if "database is locked" in em: self.conn.hsrv.broker.say("log_stacks") @@ -809,7 +809,7 @@ class HttpCli(object): if k in skip: continue - t = "{}={}".format(quotep(k), quotep(v)) + t = "%s=%s" % (quotep(k), quotep(v)) ret.append(t.replace(" ", "+").rstrip("=")) if not ret: @@ -857,7 +857,8 @@ class HttpCli(object): oh = self.out_headers origin = origin.lower() good_origins = self.args.acao + [ - "{}://{}".format( + "%s://%s" + % ( "https" if self.is_https else "http", self.host.lower().split(":")[0], ) @@ -1054,7 +1055,7 @@ class HttpCli(object): self.can_read = self.can_write = self.can_get = False if not self.can_read and not self.can_write and not self.can_get: - self.log("inaccessible: [{}]".format(self.vpath)) + self.log("inaccessible: [%s]" % (self.vpath,)) raise Pebkac(401, "authenticate") from .dxml import parse_xml @@ -1404,7 +1405,7 @@ class HttpCli(object): if txt and len(txt) == orig_len: raise Pebkac(500, "chunk slicing failed") - buf = "{:x}\r\n".format(len(buf)).encode(enc) + buf + buf = ("%x\r\n" % (len(buf),)).encode(enc) + buf self.s.sendall(buf + b"\r\n") return txt @@ -4231,7 +4232,7 @@ class HttpCli(object): if icur: lmte = list(mte) if self.can_admin: - lmte += ["up_ip", ".up_at"] + lmte.extend(("up_ip", ".up_at")) taglist = [k for k in lmte if k in tagset] for fe in dirs: diff --git a/copyparty/httpconn.py b/copyparty/httpconn.py index 60c8e729..90f40a93 100644 --- a/copyparty/httpconn.py +++ b/copyparty/httpconn.py @@ -93,7 +93,7 @@ class HttpConn(object): self.rproxy = ip self.ip = ip - self.log_src = "{} \033[{}m{}".format(ip, color, self.addr[1]).ljust(26) + self.log_src = ("%s \033[%dm%d" % (ip, color, self.addr[1])).ljust(26) return self.log_src def respath(self, res_name: str) -> str: @@ -176,7 +176,7 @@ class HttpConn(object): self.s = ctx.wrap_socket(self.s, server_side=True) msg = [ - "\033[1;3{:d}m{}".format(c, s) + "\033[1;3%dm%s" % (c, s) for c, s in zip([0, 5, 0], self.s.cipher()) # type: ignore ] self.log(" ".join(msg) + "\033[0m") diff --git a/copyparty/httpsrv.py b/copyparty/httpsrv.py index 2166bdeb..6e7daf9e 100644 --- a/copyparty/httpsrv.py +++ b/copyparty/httpsrv.py @@ -366,7 +366,7 @@ class HttpSrv(object): if not self.t_periodic: name = "hsrv-pt" if self.nid: - name += "-{}".format(self.nid) + name += "-%d" % (self.nid,) self.t_periodic = Daemon(self.periodic, name) @@ -385,7 +385,7 @@ class HttpSrv(object): Daemon( self.thr_client, - "httpconn-{}-{}".format(addr[0].split(".", 2)[-1][-6:], addr[1]), + "httpconn-%s-%d" % (addr[0].split(".", 2)[-1][-6:], addr[1]), (sck, addr), ) @@ -402,9 +402,7 @@ class HttpSrv(object): try: sck, addr = task me = threading.current_thread() - me.name = "httpconn-{}-{}".format( - addr[0].split(".", 2)[-1][-6:], addr[1] - ) + me.name = "httpconn-%s-%d" % (addr[0].split(".", 2)[-1][-6:], addr[1]) self.thr_client(sck, addr) me.name = self.name + "-poolw" except Exception as ex: diff --git a/copyparty/ico.py b/copyparty/ico.py index 57da0928..00da00dd 100644 --- a/copyparty/ico.py +++ b/copyparty/ico.py @@ -27,13 +27,13 @@ class Ico(object): c1 = colorsys.hsv_to_rgb(zb[0] / 256.0, 1, 0.3) c2 = colorsys.hsv_to_rgb(zb[0] / 256.0, 0.8 if HAVE_PILF else 1, 1) ci = [int(x * 255) for x in list(c1) + list(c2)] - c = "".join(["{:02x}".format(x) for x in ci]) + c = "".join(["%02x" % (x,) for x in ci]) w = 100 h = 30 if not self.args.th_no_crop and as_thumb: sw, sh = self.args.th_size.split("x") - h = int(100 / (float(sw) / float(sh))) + h = int(100.0 / (float(sw) / float(sh))) w = 100 if chrome: @@ -47,12 +47,12 @@ class Ico(object): # [.lt] are hard to see lowercase / unspaced ext2 = re.sub("(.)", "\\1 ", ext).upper() - h = int(128 * h / w) + h = int(128.0 * h / w) w = 128 img = Image.new("RGB", (w, h), "#" + c[:6]) pb = ImageDraw.Draw(img) _, _, tw, th = pb.textbbox((0, 0), ext2, font_size=16) - xy = ((w - tw) // 2, (h - th) // 2) + xy = (int((w - tw) / 2), int((h - th) / 2)) pb.text(xy, ext2, fill="#" + c[6:], font_size=16) img = img.resize((w * 2, h * 2), Image.NEAREST) @@ -68,7 +68,7 @@ class Ico(object): # svg: 3s, cache: 6s, this: 8s from PIL import Image, ImageDraw - h = int(64 * h / w) + h = int(64.0 * h / w) w = 64 img = Image.new("RGB", (w, h), "#" + c[:6]) pb = ImageDraw.Draw(img) diff --git a/copyparty/mtag.py b/copyparty/mtag.py index e32d0ece..d630fb63 100644 --- a/copyparty/mtag.py +++ b/copyparty/mtag.py @@ -240,7 +240,7 @@ def parse_ffprobe(txt: str) -> tuple[dict[str, tuple[int, Any]], dict[str, list[ if "/" in fps: fa, fb = fps.split("/") try: - fps = int(fa) * 1.0 / int(fb) + fps = float(fa) / float(fb) except: fps = 9001 diff --git a/copyparty/star.py b/copyparty/star.py index 078b1169..5a4663ba 100644 --- a/copyparty/star.py +++ b/copyparty/star.py @@ -65,21 +65,21 @@ class StreamTar(StreamArc): cmp = re.sub(r"[^a-z0-9]*pax[^a-z0-9]*", "", cmp) try: - cmp, lv = cmp.replace(":", ",").split(",") - lv = int(lv) + cmp, zs = cmp.replace(":", ",").split(",") + lv = int(zs) except: - lv = None + lv = -1 arg = {"name": None, "fileobj": self.qfile, "mode": "w", "format": fmt} if cmp == "gz": fun = tarfile.TarFile.gzopen - arg["compresslevel"] = lv if lv is not None else 3 + arg["compresslevel"] = lv if lv >= 0 else 3 elif cmp == "bz2": fun = tarfile.TarFile.bz2open - arg["compresslevel"] = lv if lv is not None else 2 + arg["compresslevel"] = lv if lv >= 0 else 2 elif cmp == "xz": fun = tarfile.TarFile.xzopen - arg["preset"] = lv if lv is not None else 1 + arg["preset"] = lv if lv >= 0 else 1 else: fun = tarfile.open arg["mode"] = "w|" diff --git a/copyparty/svchub.py b/copyparty/svchub.py index cf74ce68..5c916642 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -474,7 +474,7 @@ class SvcHub(object): import resource soft, hard = [ - x if x > 0 else 1024 * 1024 + int(x) if x > 0 else 1024 * 1024 for x in list(resource.getrlimit(resource.RLIMIT_NOFILE)) ] except: @@ -791,7 +791,7 @@ class SvcHub(object): self.logf.flush() now = time.time() - if now >= self.next_day: + if int(now) >= self.next_day: self._set_next_day() def _set_next_day(self) -> None: @@ -819,7 +819,7 @@ class SvcHub(object): """handles logging from all components""" with self.log_mutex: now = time.time() - if now >= self.next_day: + if int(now) >= self.next_day: dt = datetime.fromtimestamp(now, UTC) zs = "{}\n" if self.no_ansi else "\033[36m{}\033[0m\n" zs = zs.format(dt.strftime("%Y-%m-%d")) diff --git a/copyparty/th_srv.py b/copyparty/th_srv.py index 64f24f0e..27a16bc9 100644 --- a/copyparty/th_srv.py +++ b/copyparty/th_srv.py @@ -102,7 +102,7 @@ def thumb_path(histpath: str, rem: str, mtime: float, fmt: str, ffa: set[str]) - rd += "\n" + fmt h = hashlib.sha512(afsenc(rd)).digest() b64 = base64.urlsafe_b64encode(h).decode("ascii")[:24] - rd = "{}/{}/".format(b64[:2], b64[2:4]).lower() + b64 + rd = ("%s/%s/" % (b64[:2], b64[2:4])).lower() + b64 # could keep original filenames but this is safer re pathlen h = hashlib.sha512(afsenc(fn)).digest() @@ -115,7 +115,7 @@ def thumb_path(histpath: str, rem: str, mtime: float, fmt: str, ffa: set[str]) - fmt = "webp" if fc == "w" else "png" if fc == "p" else "jpg" cat = "th" - return "{}/{}/{}/{}.{:x}.{}".format(histpath, cat, rd, fn, int(mtime), fmt) + return "%s/%s/%s/%s.%x.%s" % (histpath, cat, rd, fn, int(mtime), fmt) class ThumbSrv(object): @@ -382,7 +382,7 @@ class ThumbSrv(object): # method 0 = pillow-default, fast # method 4 = ffmpeg-default # method 6 = max, slow - fmts += ["RGBA", "LA"] + fmts.extend(("RGBA", "LA")) args["method"] = 6 else: # default q = 75 diff --git a/copyparty/up2k.py b/copyparty/up2k.py index 0a9c9723..1ce4f8c3 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -987,7 +987,7 @@ class Up2k(object): excl = [x.replace("/", "\\") for x in excl] else: # ~/.wine/dosdevices/z:/ and such - excl += ["/dev", "/proc", "/run", "/sys"] + excl.extend(("/dev", "/proc", "/run", "/sys")) rtop = absreal(top) n_add = n_rm = 0 @@ -1089,7 +1089,7 @@ class Up2k(object): cv = "" assert self.pp and self.mem_cur - self.pp.msg = "a{} {}".format(self.pp.n, cdir) + self.pp.msg = "a%d %s" % (self.pp.n, cdir) rd = cdir[len(top) :].strip("/") if WINDOWS: @@ -1164,8 +1164,8 @@ class Up2k(object): continue if not sz and ( - "{}.PARTIAL".format(iname) in partials - or ".{}.PARTIAL".format(iname) in partials + "%s.PARTIAL" % (iname,) in partials + or ".%s.PARTIAL" % (iname,) in partials ): # placeholder for unfinished upload continue @@ -1261,7 +1261,7 @@ class Up2k(object): else: at = 0 - self.pp.msg = "a{} {}".format(self.pp.n, abspath) + self.pp.msg = "a%d %s" % (self.pp.n, abspath) if nohash or not sz: wark = up2k_wark_from_metadata(self.salt, sz, lmod, rd, fn) @@ -1361,7 +1361,7 @@ class Up2k(object): rd = drd abspath = djoin(top, rd) - self.pp.msg = "b{} {}".format(ndirs - nchecked, abspath) + self.pp.msg = "b%d %s" % (ndirs - nchecked, abspath) try: if os.path.isdir(abspath): continue @@ -1713,7 +1713,7 @@ class Up2k(object): cur.execute(q, (w[:16],)) abspath = djoin(ptop, rd, fn) - self.pp.msg = "c{} {}".format(nq, abspath) + self.pp.msg = "c%d %s" % (nq, abspath) if not mpool: n_tags = self._tagscan_file(cur, entags, w, abspath, ip, at) else: @@ -1770,7 +1770,7 @@ class Up2k(object): if c2.execute(q, (row[0][:16],)).fetchone(): continue - gf.write("{}\n".format("\x00".join(row)).encode("utf-8")) + gf.write(("%s\n" % ("\x00".join(row),)).encode("utf-8")) n += 1 c2.close() @@ -2700,7 +2700,7 @@ class Up2k(object): else: dip = self.hub.iphash.s(ip) - suffix = "-{:.6f}-{}".format(ts, dip) + suffix = "-%.6f-%s" % (ts, dip) with ren_open(fname, "wb", fdir=fdir, suffix=suffix) as zfw: return zfw["orz"][1] @@ -2915,7 +2915,7 @@ class Up2k(object): except: pass - z2 += [upt] + z2.append(upt) if self.idx_wark(vflags, *z2): del self.registry[ptop][wark] else: @@ -3208,9 +3208,9 @@ class Up2k(object): except: pass - volpath = "{}/{}".format(vrem, fn).strip("/") - vpath = "{}/{}".format(dbv.vpath, volpath).strip("/") - self.log("rm {}\n {}".format(vpath, abspath)) + volpath = ("%s/%s" % (vrem, fn)).strip("/") + vpath = ("%s/%s" % (dbv.vpath, volpath)).strip("/") + self.log("rm %s\n %s" % (vpath, abspath)) _ = dbv.get(volpath, uname, *permsets[0]) if xbd: if not runhook( @@ -3742,7 +3742,7 @@ class Up2k(object): return [] if self.pp: - mb = int(fsz / 1024 / 1024) + mb = fsz // (1024 * 1024) self.pp.msg = prefix + str(mb) + suffix hashobj = hashlib.sha512() @@ -3807,7 +3807,7 @@ class Up2k(object): else: dip = self.hub.iphash.s(job["addr"]) - suffix = "-{:.6f}-{}".format(job["t0"], dip) + suffix = "-%.6f-%s" % (job["t0"], dip) with ren_open(tnam, "wb", fdir=pdir, suffix=suffix) as zfw: f, job["tnam"] = zfw["orz"] abspath = djoin(pdir, job["tnam"]) @@ -4138,6 +4138,6 @@ def up2k_wark_from_hashlist(salt: str, filesize: int, hashes: list[str]) -> str: def up2k_wark_from_metadata(salt: str, sz: int, lastmod: int, rd: str, fn: str) -> str: - ret = sfsenc("{}\n{}\n{}\n{}\n{}".format(salt, lastmod, sz, rd, fn)) + ret = sfsenc("%s\n%d\n%d\n%s\n%s" % (salt, lastmod, sz, rd, fn)) ret = base64.urlsafe_b64encode(hashlib.sha512(ret).digest()) - return "#{}".format(ret.decode("ascii"))[:44] + return ("#%s" % (ret.decode("ascii"),))[:44] diff --git a/copyparty/util.py b/copyparty/util.py index 9de08a72..b7c93568 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -849,7 +849,7 @@ class MTHash(object): ex = ex or str(qe) if pp: - mb = int((fsz - nch * chunksz) / 1024 / 1024) + mb = (fsz - nch * chunksz) // (1024 * 1024) pp.msg = prefix + str(mb) + suffix if ex: @@ -1071,7 +1071,7 @@ def uprint(msg: str) -> None: def nuprint(msg: str) -> None: - uprint("{}\n".format(msg)) + uprint("%s\n" % (msg,)) def dedent(txt: str) -> str: @@ -1094,10 +1094,10 @@ def rice_tid() -> str: def trace(*args: Any, **kwargs: Any) -> None: t = time.time() stack = "".join( - "\033[36m{}\033[33m{}".format(x[0].split(os.sep)[-1][:-3], x[1]) + "\033[36m%s\033[33m%s" % (x[0].split(os.sep)[-1][:-3], x[1]) for x in traceback.extract_stack()[3:-1] ) - parts = ["{:.6f}".format(t), rice_tid(), stack] + parts = ["%.6f" % (t,), rice_tid(), stack] if args: parts.append(repr(args)) @@ -1114,17 +1114,17 @@ def alltrace() -> str: threads: dict[str, types.FrameType] = {} names = dict([(t.ident, t.name) for t in threading.enumerate()]) for tid, stack in sys._current_frames().items(): - name = "{} ({:x})".format(names.get(tid), tid) + name = "%s (%x)" % (names.get(tid), tid) threads[name] = stack rret: list[str] = [] bret: list[str] = [] for name, stack in sorted(threads.items()): - ret = ["\n\n# {}".format(name)] + ret = ["\n\n# %s" % (name,)] pad = None for fn, lno, name, line in traceback.extract_stack(stack): fn = os.sep.join(fn.split(os.sep)[-3:]) - ret.append('File: "{}", line {}, in {}'.format(fn, lno, name)) + ret.append('File: "%s", line %d, in %s' % (fn, lno, name)) if line: ret.append(" " + str(line.strip())) if "self.not_empty.wait()" in line: @@ -1133,7 +1133,7 @@ def alltrace() -> str: if pad: bret += [ret[0]] + [pad + x for x in ret[1:]] else: - rret += ret + rret.extend(ret) return "\n".join(rret + bret) + "\n" @@ -1229,9 +1229,9 @@ def vol_san(vols: list["VFS"], txt: bytes) -> bytes: def min_ex(max_lines: int = 8, reverse: bool = False) -> str: et, ev, tb = sys.exc_info() stb = traceback.extract_tb(tb) - fmt = "{} @ {} <{}>: {}" - ex = [fmt.format(fp.split(os.sep)[-1], ln, fun, txt) for fp, ln, fun, txt in stb] - ex.append("[{}] {}".format(et.__name__ if et else "(anonymous)", ev)) + fmt = "%s @ %d <%s>: %s" + ex = [fmt % (fp.split(os.sep)[-1], ln, fun, txt) for fp, ln, fun, txt in stb] + ex.append("[%s] %s" % (et.__name__ if et else "(anonymous)", ev)) return "\n".join(ex[-max_lines:][:: -1 if reverse else 1]) @@ -1282,7 +1282,7 @@ def ren_open( with fun(fsenc(fpath), *args, **kwargs) as f: if b64: assert fdir - fp2 = "fn-trunc.{}.txt".format(b64) + fp2 = "fn-trunc.%s.txt" % (b64,) fp2 = os.path.join(fdir, fp2) with open(fsenc(fp2), "wb") as f2: f2.write(orig_name.encode("utf-8")) @@ -1311,7 +1311,7 @@ def ren_open( raise if not b64: - zs = "{}\n{}".format(orig_name, suffix).encode("utf-8", "replace") + zs = ("%s\n%s" % (orig_name, suffix)).encode("utf-8", "replace") zs = hashlib.sha512(zs).digest()[:12] b64 = base64.urlsafe_b64encode(zs).decode("utf-8") @@ -1331,7 +1331,7 @@ def ren_open( # okay do the first letter then ext = "." + ext[2:] - fname = "{}~{}{}".format(bname, b64, ext) + fname = "%s~%s%s" % (bname, b64, ext) class MultipartParser(object): @@ -1608,7 +1608,7 @@ def rand_name(fdir: str, fn: str, rnd: int) -> str: break nc = rnd + extra - nb = int((6 + 6 * nc) / 8) + nb = (6 + 6 * nc) // 8 zb = os.urandom(nb) zb = base64.urlsafe_b64encode(zb) fn = zb[:nc].decode("utf-8") + ext @@ -1711,7 +1711,7 @@ def get_spd(nbyte: int, t0: float, t: Optional[float] = None) -> str: bps = nbyte / ((t - t0) + 0.001) s1 = humansize(nbyte).replace(" ", "\033[33m").replace("iB", "") s2 = humansize(bps).replace(" ", "\033[35m").replace("iB", "") - return "{} \033[0m{}/s\033[0m".format(s1, s2) + return "%s \033[0m%s/s\033[0m" % (s1, s2) def s2hms(s: float, optional_h: bool = False) -> str: @@ -1719,9 +1719,9 @@ def s2hms(s: float, optional_h: bool = False) -> str: h, s = divmod(s, 3600) m, s = divmod(s, 60) if not h and optional_h: - return "{}:{:02}".format(m, s) + return "%d:%02d" % (m, s) - return "{}:{:02}:{:02}".format(h, m, s) + return "%d:%02d:%02d" % (h, m, s) def djoin(*paths: str) -> str: @@ -2191,7 +2191,7 @@ def read_socket_chunked( raise Pebkac(400, t.format(x)) if log: - log("receiving {} byte chunk".format(chunklen)) + log("receiving %d byte chunk" % (chunklen,)) for chunk in read_socket(sr, chunklen): yield chunk @@ -2964,7 +2964,7 @@ def visual_length(txt: str) -> int: pend = None else: if ch == "\033": - pend = "{0}".format(ch) + pend = "%s" % (ch,) else: co = ord(ch) # the safe parts of latin1 and cp437 (no greek stuff) diff --git a/scripts/sfx.py b/scripts/sfx.py index 0ece86e4..949f85d1 100644 --- a/scripts/sfx.py +++ b/scripts/sfx.py @@ -262,7 +262,7 @@ def unpack(): final = opj(top, name) san = opj(final, "copyparty/up2k.py") for suf in range(0, 9001): - withpid = "{}.{}.{}".format(name, os.getpid(), suf) + withpid = "%s.%d.%s" % (name, os.getpid(), suf) mine = opj(top, withpid) if not ofe(mine): break @@ -285,8 +285,8 @@ def unpack(): ck = hashfile(tar) if ck != CKSUM: - t = "\n\nexpected {} ({} byte)\nobtained {} ({} byte)\nsfx corrupt" - raise Exception(t.format(CKSUM, SIZE, ck, sz)) + t = "\n\nexpected %s (%d byte)\nobtained %s (%d byte)\nsfx corrupt" + raise Exception(t % (CKSUM, SIZE, ck, sz)) with tarfile.open(tar, "r:bz2") as tf: # this is safe against traversal