1
0
Fork 0

Use tqdm instead of home-made progressbar

This commit is contained in:
Félix Piédallu 2024-02-11 20:04:34 +01:00
parent 350d083122
commit 20081a9620

View file

@ -12,6 +12,8 @@ from datetime import datetime
import requests import requests
import toml import toml
import tqdm
from tqdm.contrib.logging import logging_redirect_tqdm
# add apps/tools to sys.path # add apps/tools to sys.path
sys.path.insert(0, str(Path(__file__).parent.parent)) sys.path.insert(0, str(Path(__file__).parent.parent))
@ -432,28 +434,6 @@ class AppAutoUpdater:
return content return content
# Progress bar helper, stolen from https://stackoverflow.com/a/34482761
def progressbar(it, prefix="", size=60, file=sys.stdout):
it = list(it)
count = len(it)
def show(j, name=""):
name += " "
x = int(size * j / count)
file.write(
"\n%s[%s%s] %i/%i %s\n"
% (prefix, "#" * x, "." * (size - x), j, count, name)
)
file.flush()
show(0)
for i, item in enumerate(it):
show(i + 1, item)
yield item
file.write("\n")
file.flush()
def paste_on_haste(data): def paste_on_haste(data):
# NB: we hardcode this here and can't use the yunopaste command # NB: we hardcode this here and can't use the yunopaste command
# because this script runs on the same machine than haste is hosted on... # because this script runs on the same machine than haste is hosted on...
@ -496,7 +476,9 @@ def main() -> None:
apps_failed = [] apps_failed = []
apps_failed_details = {} apps_failed_details = {}
apps_updated = [] apps_updated = []
for app in progressbar(apps_to_run_auto_update_for(), "Checking: ", 40):
with logging_redirect_tqdm():
for app in tqdm.tqdm(apps_to_run_auto_update_for(), ascii=" ·#"):
try: try:
updated = AppAutoUpdater(app).run() updated = AppAutoUpdater(app).run()
except Exception as e: except Exception as e: