diff options
author | Benjamin Klimczak <benjamin.klimczak@arm.com> | 2024-03-21 17:33:17 +0000 |
---|---|---|
committer | Benjamin Klimczak <benjamin.klimczak@arm.com> | 2024-03-22 10:06:28 +0000 |
commit | c7ee5b783f044d7ff641773aa385840f5ff944cc (patch) | |
tree | 297f308978b00282d8ebd3a1f71e1ae5e678a767 /src/mlia/utils/proc.py | |
parent | 508281df31dc3c18f2e007f4dd505160342a681a (diff) | |
download | mlia-c7ee5b783f044d7ff641773aa385840f5ff944cc.tar.gz |
refactor: Backend dependencies and more
- Add backend dependencies: One backend can now depend on another
backend.
- Re-factor 'DownloadArtifact':
- Rename 'DownloadArtifact' to 'DownloadConfig'
- Remove attributes 'name' and 'version' not relevant for downloads
- Add helper properties:
- 'filename' parses the URL to extract the file name from the end
- 'headers' calls the function to generate a HTML header for the
download
- Add OutputLogger helper class
- Re-factor handling of backend configurations in the target profiles.
Change-Id: Ifda6cf12c375d0c1747d7e4130a0370d22c3d33a
Signed-off-by: Benjamin Klimczak <benjamin.klimczak@arm.com>
Diffstat (limited to 'src/mlia/utils/proc.py')
-rw-r--r-- | src/mlia/utils/proc.py | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/src/mlia/utils/proc.py b/src/mlia/utils/proc.py index d11bfc5..236854e 100644 --- a/src/mlia/utils/proc.py +++ b/src/mlia/utils/proc.py @@ -6,6 +6,7 @@ from __future__ import annotations import logging import subprocess # nosec from dataclasses import dataclass +from functools import partial from pathlib import Path from typing import Callable from typing import Generator @@ -45,6 +46,18 @@ def command_output(command: Command) -> Generator[str, None, None]: OutputConsumer = Callable[[str], None] +class OutputLogger: + """Log process output to the given logger with the given level.""" + + def __init__(self, logger_: logging.Logger, level: int = logging.DEBUG) -> None: + """Create log function with the appropriate log level set.""" + self.log_fn = partial(logger_.log, level) + + def __call__(self, line: str) -> None: + """Redirect output to the logger.""" + self.log_fn(line) + + def process_command_output( command: Command, consumers: list[OutputConsumer], |