From 2fbdc0a85ea00f969339c9428100269404c9dcda Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 2 Dec 2022 23:42:46 +0000 Subject: [PATCH] misc fixes / cleanup --- copyparty/__main__.py | 7 ++++++- copyparty/httpsrv.py | 3 +++ copyparty/svchub.py | 2 +- copyparty/szip.py | 3 ++- copyparty/tcpsrv.py | 7 ++++++- copyparty/web/browser.js | 2 +- scripts/make-sfx.sh | 30 ++++++++++++++---------------- 7 files changed, 33 insertions(+), 21 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index ddc46445..3c7cd044 100755 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -947,14 +947,19 @@ def main(argv: Optional[list[str]] = None) -> None: argv[idx] = nk time.sleep(2) + da = len(argv) == 1 try: - if len(argv) == 1: + if da: argv.extend(["--qr"]) if ANYWIN or not os.geteuid(): argv.extend(["-p80,443,3923", "--ign-ebind"]) except: pass + if da: + t = "no arguments provided; will use {}\n" + lprint(t.format(" ".join(argv[1:]))) + nc = 1024 try: import resource diff --git a/copyparty/httpsrv.py b/copyparty/httpsrv.py index 8dc06e0f..af10334d 100644 --- a/copyparty/httpsrv.py +++ b/copyparty/httpsrv.py @@ -280,6 +280,9 @@ class HttpSrv(object): addr = (cip, cport) except (OSError, socket.error) as ex: + if self.stopping: + break + self.log(self.name, "accept({}): {}".format(fno, ex), c=6) time.sleep(0.02) continue diff --git a/copyparty/svchub.py b/copyparty/svchub.py index d24b7c8f..39b46c40 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -526,8 +526,8 @@ class SvcHub(object): Daemon(self.ssdp.stop) slp = time.time() + 0.5 - self.tcpsrv.shutdown() self.broker.shutdown() + self.tcpsrv.shutdown() self.up2k.shutdown() if self.thumbsrv: self.thumbsrv.shutdown() diff --git a/copyparty/szip.py b/copyparty/szip.py index 06bae7e0..4207d682 100644 --- a/copyparty/szip.py +++ b/copyparty/szip.py @@ -269,6 +269,7 @@ class StreamZip(StreamArc): yield self._ct(buf) def gen(self) -> Generator[bytes, None, None]: + errf: dict[str, Any] = {} errors = [] try: for f in self.fgen: @@ -309,5 +310,5 @@ class StreamZip(StreamArc): ecdr, _ = gen_ecdr(self.items, cdir_pos, cdir_end) yield self._ct(ecdr) finally: - if errors: + if errf: bos.unlink(errf["ap"]) diff --git a/copyparty/tcpsrv.py b/copyparty/tcpsrv.py index 1188e9aa..d3b1b026 100644 --- a/copyparty/tcpsrv.py +++ b/copyparty/tcpsrv.py @@ -576,4 +576,9 @@ class TcpSrv(object): qr = qr.replace("\n", "\033[K\n") + "\033[K" # win10do cc = " \033[0;38;5;{0};47;48;5;{1}m" if fg else " \033[0;30;47m" t = cc + "\n{2}\033[999G\033[0m\033[J" - return txt + t.format(fg, bg, qr) + t = t.format(fg, bg, qr) + if ANYWIN: + # prevent color loss on terminal resize + t = t.replace("\n", "`\n`") + + return txt + t diff --git a/copyparty/web/browser.js b/copyparty/web/browser.js index 3ac6dbc5..123597f1 100644 --- a/copyparty/web/browser.js +++ b/copyparty/web/browser.js @@ -4586,7 +4586,7 @@ document.onkeydown = function (e) { ], [ L.s_ta, - ["tags", "tags", L.s_t1, "30", "^nhato"] + ["tags", "tags", L.s_t1, "30", "^ゲリラ$"] ], [ L.s_ad, diff --git a/scripts/make-sfx.sh b/scripts/make-sfx.sh index dae7b303..4d042d35 100755 --- a/scripts/make-sfx.sh +++ b/scripts/make-sfx.sh @@ -137,6 +137,10 @@ tmpdir="$( awk '/./ {print; exit}' )" +necho() { + printf '\033[G%s\033[K' "$*" +} + [ $repack ] && { old="$tmpdir/pe-copyparty.$(id -u)" echo "repack of files in $old" @@ -145,7 +149,7 @@ tmpdir="$( } [ $repack ] || { - echo collecting ipaddress + necho collecting ipaddress f="../build/ipaddress-1.0.23.tar.gz" [ -e "$f" ] || (url=https://files.pythonhosted.org/packages/b9/9a/3e9da40ea28b8210dd6504d3fe9fe7e013b62bf45902b458d1cdc3c34ed9/ipaddress-1.0.23.tar.gz; @@ -156,7 +160,7 @@ tmpdir="$( mv ipaddress-*/ipaddress.py py37/ rm -rf ipaddress-* - echo collecting jinja2 + necho collecting jinja2 f="../build/Jinja2-2.11.3.tar.gz" [ -e "$f" ] || (url=https://files.pythonhosted.org/packages/4f/e7/65300e6b32e69768ded990494809106f87da1d436418d5f1367ed3966fd7/Jinja2-2.11.3.tar.gz; @@ -166,7 +170,7 @@ tmpdir="$( mv Jinja2-*/src/jinja2 . rm -rf Jinja2-* - echo collecting markupsafe + necho collecting markupsafe f="../build/MarkupSafe-1.1.1.tar.gz" [ -e "$f" ] || (url=https://files.pythonhosted.org/packages/b9/2e/64db92e53b86efccfaea71321f597fa2e1b2bd3853d8ce658568f7a13094/MarkupSafe-1.1.1.tar.gz; @@ -179,7 +183,7 @@ tmpdir="$( mkdir j2/ mv {markupsafe,jinja2} j2/ - echo collecting pyftpdlib + necho collecting pyftpdlib f="../build/pyftpdlib-1.5.6.tar.gz" [ -e "$f" ] || (url=https://github.com/giampaolo/pyftpdlib/archive/refs/tags/release-1.5.6.tar.gz; @@ -192,7 +196,7 @@ tmpdir="$( mkdir ftp/ mv pyftpdlib ftp/ - echo collecting asyncore, asynchat + necho collecting asyncore, asynchat for n in asyncore.py asynchat.py; do f=../build/$n [ -e "$f" ] || @@ -200,7 +204,7 @@ tmpdir="$( wget -O$f "$url" || curl -L "$url" >$f) done - echo collecting python-magic + necho collecting python-magic v=0.4.27 f="../build/python-magic-$v.tar.gz" [ -e "$f" ] || @@ -220,7 +224,7 @@ tmpdir="$( # enable this to dynamically remove type hints at startup, # in case a future python version can use them for performance true || ( - echo collecting strip-hints + necho collecting strip-hints f=../build/strip-hints-0.1.10.tar.gz [ -e $f ] || (url=https://files.pythonhosted.org/packages/9c/d4/312ddce71ee10f7e0ab762afc027e07a918f1c0e1be5b0069db5b0e7542d/strip-hints-0.1.10.tar.gz; @@ -236,7 +240,8 @@ tmpdir="$( cp -pR ../scripts/py2 . # msys2 tar is bad, make the best of it - echo collecting source + necho collecting source + echo [ $clean ] && { (cd .. && git archive hovudstraum >tar) && tar -xf ../tar copyparty (cd .. && tar -cf tar copyparty/web/deps) && tar -xf ../tar @@ -258,7 +263,7 @@ tmpdir="$( exit 1 } rm "$f1" - cp -pv "$f2" "$f1" + cp -p "$f2" "$f1" ); done # insert asynchat @@ -329,13 +334,6 @@ find -type f -name ._\* | while IFS= read -r f; do cmp <(printf '\x00\x05\x16') echo use smol web deps rm -f copyparty/web/deps/*.full.* copyparty/web/dbg-* copyparty/web/Makefile -# it's fine dw -grep -lE '\.full\.(js|css)' copyparty/web/* | -while IFS= read -r x; do - sed -r 's/\.full\.(js|css)/.\1/g' <"$x" >t - tmv "$x" -done - find copyparty | LC_ALL=C sort | sed 's/\.gz$//;s/$/,/' > have cat have | while IFS= read -r x; do grep -qF -- "$x" ../scripts/sfx.ls || {