Skip to content

Commit

Permalink
images: add conditional printing based on sys.stdout.isatty()
Browse files Browse the repository at this point in the history
  • Loading branch information
yzqzss committed Mar 23, 2024
1 parent d1612ba commit a1b2beb
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions wikiteam3/dumpgenerator/dump/image/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit a1b2beb

Please sign in to comment.