From f1646b96caf1828918bd076ab0e51f306bcd8c78 Mon Sep 17 00:00:00 2001 From: ed Date: Tue, 1 Oct 2024 18:35:36 +0000 Subject: [PATCH] dist: strip some pointless code --- bin/partyfuse.py | 10 ++++++++++ copyparty/__init__.py | 1 + copyparty/util.py | 2 ++ scripts/make-sfx.sh | 6 +++--- scripts/strip_hints/a.py | 10 ++++++++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/bin/partyfuse.py b/bin/partyfuse.py index 29a53d79..70854c55 100755 --- a/bin/partyfuse.py +++ b/bin/partyfuse.py @@ -363,8 +363,10 @@ class Gateway(object): ctype = r.getheader("Content-Type", "") if ctype == "application/json": parser = self.parse_jls + # !rm.yes> elif ctype.startswith("text/html"): parser = self.parse_html + # !rm.no> else: info("listdir on file (%s): %r", ctype, path) raise FuseOSError(errno.ENOENT) @@ -418,6 +420,7 @@ class Gateway(object): return ret + # !rm.yes> def parse_html(self, sck): ret = {} rem = b"" @@ -465,6 +468,7 @@ class Gateway(object): ret[fname] = self.stat_dir(ts, sz) return ret + # !rm.no> def stat_dir(self, ts, sz=4096): return { @@ -548,6 +552,7 @@ class CPPF(Operations): break return None + # !rm.yes> """ ,-------------------------------, g1>=c1, g2<=c2 |cache1 cache2| buf[g1-c1:(g1-c1)+(g2-g1)] @@ -572,6 +577,7 @@ class CPPF(Operations): |get1 get2| `---------------' """ + # !rm.no> def get_cached_file(self, path, get1, get2, file_sz): car = None @@ -802,6 +808,7 @@ class CPPF(Operations): return ret + # !rm.yes> fn = "cppf-{}-{}-{}".format(time.time(), offset, length) if False: with open(fn, "wb", len(ret)) as f: @@ -824,6 +831,7 @@ class CPPF(Operations): raise Exception("cache bork") return ret + # !rm.no> def getattr(self, path, fh=None): dbg("getattr %r", path) @@ -871,6 +879,7 @@ class CPPF(Operations): releasedir = None statfs = None + # !rm.yes> if False: # incorrect semantics but good for debugging stuff like samba and msys2 def access(self, path, mode): @@ -908,6 +917,7 @@ class CPPF(Operations): def statfs(self, path): dbg("@@ statfs [{}]".format(path)) return {} + # !rm.no> if sys.platform == "win32": # quick compat for /mingw64/bin/python3 (msys2) diff --git a/copyparty/__init__.py b/copyparty/__init__.py index 6ff96050..af43885c 100644 --- a/copyparty/__init__.py +++ b/copyparty/__init__.py @@ -73,6 +73,7 @@ web/deps/busy.mp3 web/deps/easymde.css web/deps/easymde.js web/deps/marked.js +web/deps/fuse.py web/deps/mini-fa.css web/deps/mini-fa.woff web/deps/prism.css diff --git a/copyparty/util.py b/copyparty/util.py index 5adebbc5..f2e7a930 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -761,6 +761,7 @@ class _Unrecv(object): self.buf = buf + self.buf +# !rm.yes> class _LUnrecv(object): """ with expensive debug logging @@ -815,6 +816,7 @@ class _LUnrecv(object): self.buf = buf + self.buf t = "\033[0;7mur:push\033[0;1;31m {}\n\033[0;7mur:rem:\033[0;1;35m {}\033[0m" print(t.format(buf, self.buf)) +# !rm.no> Unrecv = _Unrecv diff --git a/scripts/make-sfx.sh b/scripts/make-sfx.sh index 34ecbe2f..5b9e117d 100755 --- a/scripts/make-sfx.sh +++ b/scripts/make-sfx.sh @@ -27,14 +27,14 @@ help() { exec cat <<'EOF' # # `no-ftp` saves ~30k by removing the ftp server, disabling --ftp # +# `no-pf` saves ~12k by removing the option to download partyfuse +# # `no-tfp` saves ~10k by removing the tftp server, disabling --tftp # # `no-zm` saves ~7k by removing the zeroconf mDNS server # # `no-smb` saves ~3.5k by removing the smb / cifs server # -# `no-pf` saves ~2.8k by removing the option to download partyfuse -# # _____________________________________________________________________ # web features: # @@ -109,7 +109,7 @@ pybin=$(command -v python3 || command -v python) || { langs= use_gz= -zopf=2560 +zopf=2000 while [ ! -z "$1" ]; do case $1 in clean) clean=1 ; ;; diff --git a/scripts/strip_hints/a.py b/scripts/strip_hints/a.py index a4d80598..59aa76ec 100644 --- a/scripts/strip_hints/a.py +++ b/scripts/strip_hints/a.py @@ -61,11 +61,21 @@ def uh2(fp): # remove expensive imports too lns = [] on = True + on2 = True for ln in cs.split("\n"): if ln.startswith("if True:"): on = False continue + if ln.endswith("# !rm.yes>"): + on2 = False + continue + + if not on2: + if ln.endswith("# !rm.no>"): + on2 = True + continue + if not on and (not ln.strip() or ln.startswith(" ")): continue