Use tqdm instead of home-made progressbar
This commit is contained in:
parent
350d083122
commit
20081a9620
1 changed files with 16 additions and 34 deletions
|
@ -12,6 +12,8 @@ from datetime import datetime
|
|||
|
||||
import requests
|
||||
import toml
|
||||
import tqdm
|
||||
from tqdm.contrib.logging import logging_redirect_tqdm
|
||||
|
||||
# add apps/tools to sys.path
|
||||
sys.path.insert(0, str(Path(__file__).parent.parent))
|
||||
|
@ -432,28 +434,6 @@ class AppAutoUpdater:
|
|||
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):
|
||||
# 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...
|
||||
|
@ -496,7 +476,9 @@ def main() -> None:
|
|||
apps_failed = []
|
||||
apps_failed_details = {}
|
||||
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:
|
||||
updated = AppAutoUpdater(app).run()
|
||||
except Exception as e:
|
||||
|
|
Loading…
Reference in a new issue