From 6dbfcddcdafc25a1806e72d7e650743a5c26ab5e Mon Sep 17 00:00:00 2001 From: ed Date: Sat, 20 Jan 2024 17:26:52 +0000 Subject: [PATCH] don't print indexing progress to stdout if -q --- README.md | 2 +- copyparty/up2k.py | 2 +- copyparty/util.py | 18 +++++++++++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 91f745d0..84708dc7 100644 --- a/README.md +++ b/README.md @@ -1601,7 +1601,7 @@ interact with copyparty using non-browser clients * sharex (screenshot utility): see [./contrib/sharex.sxcu](contrib/#sharexsxcu) -* contextlet (web browser integration); see [contrib contextlet](contrib/readme.md#send-to-cppcontextletjson) +* contextlet (web browser integration); see [contrib contextlet](contrib/#send-to-cppcontextletjson) * [igloo irc](https://iglooirc.com/): Method: `post` Host: `https://you.com/up/?want=url&pw=hunter2` Multipart: `yes` File parameter: `f` diff --git a/copyparty/up2k.py b/copyparty/up2k.py index d490b717..e240051e 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -583,7 +583,7 @@ class Up2k(object): if gid: self.log("reload #{} running".format(self.gid)) - self.pp = ProgressPrinter() + self.pp = ProgressPrinter(self.log, self.args) vols = list(all_vols.values()) t0 = time.time() have_e2d = False diff --git a/copyparty/util.py b/copyparty/util.py index 546f63ce..877c7475 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -1,6 +1,7 @@ # coding: utf-8 from __future__ import print_function, unicode_literals +import argparse import base64 import contextlib import errno @@ -788,16 +789,20 @@ class ProgressPrinter(threading.Thread): periodically print progress info without linefeeds """ - def __init__(self) -> None: + def __init__(self, log: "NamedLogger", args: argparse.Namespace) -> None: threading.Thread.__init__(self, name="pp") self.daemon = True + self.log = log + self.args = args self.msg = "" self.end = False self.n = -1 self.start() def run(self) -> None: + tp = 0 msg = None + no_stdout = self.args.q fmt = " {}\033[K\r" if VT100 else " {} $\r" while not self.end: time.sleep(0.1) @@ -805,10 +810,21 @@ class ProgressPrinter(threading.Thread): continue msg = self.msg + now = time.time() + if msg and now - tp > 10: + tp = now + self.log("progress: %s" % (msg,), 6) + + if no_stdout: + continue + uprint(fmt.format(msg)) if PY2: sys.stdout.flush() + if no_stdout: + return + if VT100: print("\033[K", end="") elif msg: