From 709a067445b046efb5981b18bfb3262135606128 Mon Sep 17 00:00:00 2001 From: strohitv <45733269+strohitv@users.noreply.github.com> Date: Wed, 28 Sep 2022 17:50:54 +0200 Subject: [PATCH] use shutil instead of os for get_terminal_size() - os.get_terminal_size() does not work in many situations (i.e. when python gets called from a java program) - in these situations, it will simply throw an exception, breaking the whole script - in these cases, shutil is a high level alternative providing a fallback, allowing to still use the script --- s3s.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/s3s.py b/s3s.py index df42602..13ff6c7 100755 --- a/s3s.py +++ b/s3s.py @@ -4,7 +4,7 @@ # https://github.com/frozenpandaman/s3s # License: GPLv3 -import argparse, datetime, json, os, re, requests, sys, time, uuid +import argparse, datetime, json, os, shutil, re, requests, sys, time, uuid import msgpack from packaging import version from PIL import Image @@ -1008,7 +1008,7 @@ class SquidProgress: self.count = 0 def __call__(self): - lineend = os.get_terminal_size()[0] - 4 + lineend = shutil.get_terminal_size()[0] - 4 ika = '>=> ' if self.count % 2 == 0 else '===>' sys.stdout.write(f"\r{' '*self.count}{ika}{' '*(lineend - self.count)}") sys.stdout.flush()