From a1b2beb35b10adbbbb3c1e67ce65f98ed487bd99 Mon Sep 17 00:00:00 2001 From: yzqzss Date: Sat, 23 Mar 2024 19:48:35 +0800 Subject: [PATCH] images: add conditional printing based on sys.stdout.isatty() --- wikiteam3/dumpgenerator/dump/image/image.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/wikiteam3/dumpgenerator/dump/image/image.py b/wikiteam3/dumpgenerator/dump/image/image.py index 44a5311e..d3c7f679 100644 --- a/wikiteam3/dumpgenerator/dump/image/image.py +++ b/wikiteam3/dumpgenerator/dump/image/image.py @@ -27,6 +27,7 @@ """ NULL value for image metadata """ FILENAME_LIMIT = 240 """ Filename not be longer than 240 **bytes**. (MediaWiki r98430 2011-09-29) """ +STDOUT_IS_TTY = sys.stdout and sys.stdout.isatty() WBM_EARLIEST = 1 @@ -346,8 +347,11 @@ def get_ia_wbm_response() -> Optional[requests.Response]: if not to_download: # skip printing continue - print_msg = f" | {len(images)}=>{filename_underscore[0:50]}" - print(print_msg, " "*(73 - len(print_msg)), end="\r") + if STDOUT_IS_TTY: + print_msg = f" | {len(images)}=>{filename_underscore[0:50]}" + print(print_msg, " "*(73 - len(print_msg)), end="\r") + else: + print(f'{len(images)}=>{filename_underscore}') # NOTE: len(images) == 0 here