2022-07-11 22:22:17 +12:00
|
|
|
import logging
|
2022-07-24 10:06:35 +12:00
|
|
|
from dataclasses import dataclass
|
2022-07-11 22:22:17 +12:00
|
|
|
|
2022-07-30 18:32:55 +12:00
|
|
|
from typing_extensions import Protocol
|
2022-07-11 22:22:17 +12:00
|
|
|
|
|
|
|
|
2022-07-30 18:32:55 +12:00
|
|
|
class GetBooleanChoiceProtocol(Protocol):
|
|
|
|
def __call__(self, prompt: str, default: bool = ...) -> bool:
|
2022-08-01 19:30:31 +12:00
|
|
|
...
|
2022-07-11 22:22:17 +12:00
|
|
|
|
|
|
|
|
2022-07-30 18:32:55 +12:00
|
|
|
def get_boolean_choice(prompt: str, default: bool = True) -> bool:
|
|
|
|
return default
|
|
|
|
|
|
|
|
|
|
|
|
def verify_stdout(a0: int, a1: int, a2: float, a3: float) -> None:
|
|
|
|
print(f"Verification progress: {a0}/{a1} ({a2:.01f}%) [{a3:.1f} MiB/s]\t\r")
|
2022-07-11 22:22:17 +12:00
|
|
|
|
|
|
|
|
2022-08-03 11:33:50 +12:00
|
|
|
class DLManagerSignals:
|
|
|
|
_kill = False
|
|
|
|
_update = False
|
|
|
|
|
|
|
|
@property
|
|
|
|
def kill(self) -> bool:
|
|
|
|
self._update = False
|
|
|
|
return self._kill
|
|
|
|
|
|
|
|
@kill.setter
|
|
|
|
def kill(self, value: bool) -> None:
|
|
|
|
self._update = True
|
|
|
|
self._kill = value
|
|
|
|
|
|
|
|
@property
|
|
|
|
def update(self) -> bool:
|
|
|
|
_update = self._update
|
|
|
|
self._update = False
|
|
|
|
return _update
|
|
|
|
|
|
|
|
|
2022-07-24 10:06:35 +12:00
|
|
|
@dataclass
|
|
|
|
class LgndrIndirectStatus:
|
|
|
|
success: bool = False
|
|
|
|
message: str = ""
|
|
|
|
|
|
|
|
def __len__(self):
|
|
|
|
if self.message:
|
|
|
|
return 2
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def __bool__(self):
|
|
|
|
return self.success
|
|
|
|
|
|
|
|
def __getitem__(self, item):
|
|
|
|
if item == 0:
|
|
|
|
return self.success
|
|
|
|
elif item == 1:
|
|
|
|
return self.message
|
|
|
|
else:
|
|
|
|
raise IndexError
|
|
|
|
|
|
|
|
def __iter__(self):
|
|
|
|
return iter((self.success, self.message))
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
return self.message
|
|
|
|
|
|
|
|
|
|
|
|
class LgndrIndirectLogger:
|
2022-07-30 18:32:55 +12:00
|
|
|
def __init__(
|
|
|
|
self, status: LgndrIndirectStatus, logger: logging.Logger = None, level: int = logging.ERROR
|
|
|
|
):
|
2022-07-24 10:06:35 +12:00
|
|
|
self.logger = logger
|
|
|
|
self.level = level
|
|
|
|
self.status = status
|
|
|
|
|
|
|
|
def set_logger(self, logger: logging.Logger):
|
2022-07-21 08:33:44 +12:00
|
|
|
self.logger = logger
|
2022-07-24 10:06:35 +12:00
|
|
|
|
|
|
|
def set_level(self, level: int):
|
2022-07-21 08:33:44 +12:00
|
|
|
self.level = level
|
|
|
|
|
|
|
|
def _log(self, level: int, msg: str):
|
2022-07-24 10:06:35 +12:00
|
|
|
self.status.success = True if level < self.level else False
|
|
|
|
self.status.message = msg
|
|
|
|
if self.logger:
|
|
|
|
self.logger.log(level, msg)
|
2022-07-21 08:33:44 +12:00
|
|
|
|
|
|
|
def debug(self, msg: str):
|
|
|
|
self._log(logging.DEBUG, msg)
|
|
|
|
|
|
|
|
def info(self, msg: str):
|
|
|
|
self._log(logging.INFO, msg)
|
|
|
|
|
|
|
|
def warning(self, msg: str):
|
|
|
|
self._log(logging.WARNING, msg)
|
|
|
|
|
|
|
|
def error(self, msg: str):
|
|
|
|
self._log(logging.ERROR, msg)
|
|
|
|
|
|
|
|
def critical(self, msg: str):
|
|
|
|
self._log(logging.CRITICAL, msg)
|
|
|
|
|
|
|
|
def fatal(self, msg: str):
|
|
|
|
self.critical(msg)
|