don't print indexing progress to stdout if -q

This commit is contained in:
ed 2024-01-20 17:26:52 +00:00
parent b4e0a34193
commit 6dbfcddcda
3 changed files with 19 additions and 3 deletions

View file

@ -1601,7 +1601,7 @@ interact with copyparty using non-browser clients
* sharex (screenshot utility): see [./contrib/sharex.sxcu](contrib/#sharexsxcu) * 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` * [igloo irc](https://iglooirc.com/): Method: `post` Host: `https://you.com/up/?want=url&pw=hunter2` Multipart: `yes` File parameter: `f`

View file

@ -583,7 +583,7 @@ class Up2k(object):
if gid: if gid:
self.log("reload #{} running".format(self.gid)) self.log("reload #{} running".format(self.gid))
self.pp = ProgressPrinter() self.pp = ProgressPrinter(self.log, self.args)
vols = list(all_vols.values()) vols = list(all_vols.values())
t0 = time.time() t0 = time.time()
have_e2d = False have_e2d = False

View file

@ -1,6 +1,7 @@
# coding: utf-8 # coding: utf-8
from __future__ import print_function, unicode_literals from __future__ import print_function, unicode_literals
import argparse
import base64 import base64
import contextlib import contextlib
import errno import errno
@ -788,16 +789,20 @@ class ProgressPrinter(threading.Thread):
periodically print progress info without linefeeds 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") threading.Thread.__init__(self, name="pp")
self.daemon = True self.daemon = True
self.log = log
self.args = args
self.msg = "" self.msg = ""
self.end = False self.end = False
self.n = -1 self.n = -1
self.start() self.start()
def run(self) -> None: def run(self) -> None:
tp = 0
msg = None msg = None
no_stdout = self.args.q
fmt = " {}\033[K\r" if VT100 else " {} $\r" fmt = " {}\033[K\r" if VT100 else " {} $\r"
while not self.end: while not self.end:
time.sleep(0.1) time.sleep(0.1)
@ -805,10 +810,21 @@ class ProgressPrinter(threading.Thread):
continue continue
msg = self.msg 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)) uprint(fmt.format(msg))
if PY2: if PY2:
sys.stdout.flush() sys.stdout.flush()
if no_stdout:
return
if VT100: if VT100:
print("\033[K", end="") print("\033[K", end="")
elif msg: elif msg: