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
This commit is contained in:
strohitv
2022-09-28 17:50:54 +02:00
committed by GitHub
parent 8d76056143
commit 709a067445

4
s3s.py
View File

@@ -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()