1
0
Fork 0

Compare commits

...

3 commits

Author SHA1 Message Date
acacf19a12
generate: container: Drop or change removed log functions
Either drop the invocations or change them to log_error().

Signed-off-by: Enno Tensing <tenno@suij.in>
2025-08-01 19:46:14 +02:00
d097cedc6b
generate: log: Simplify the Log class
Drop hard Log Levels and log_info() and _debug()

Signed-off-by: Enno Tensing <tenno@suij.in>
2025-08-01 19:41:25 +02:00
0654f06a71
generate: container: The correct data type is guaranteed by maybe_or()
Signed-off-by: Enno Tensing <tenno@suij.in>
2025-08-01 19:28:34 +02:00
3 changed files with 13 additions and 61 deletions

View file

@ -78,22 +78,6 @@ class Cgroup:
namespace = maybe_or(val, "namespace", "")
how = maybe_or(val, "how", "")
if not isinstance(config, list):
logger.log_warning("Config key in cgroup Config is invalid!")
config = []
if not isinstance(parent, str):
logger.log_warning("Parent key in cgroup Config is invalid!")
parent = ""
if not isinstance(namespace, str):
logger.log_warning("Namespace key in cgroup Config is invalid!")
namespace = ""
if not isinstance(how, str):
logger.log_warning("How key in cgroup Config is invalid!")
how = ""
if how == "split" and parent != "":
logger.log_warning(
"Split cgroups can not be combined with a cgroup parent!"

View file

@ -34,23 +34,21 @@ def load_container_config(file: Path, log: Log) -> dict | None:
data = json.load(fp)
except json.JSONDecodeError as e:
log.log_error(f"{file.name} is not a valid JSON file!")
log.log_debug(f"Exception: {e}")
log.log_error(f"Exception: {e}")
return None
except UnicodeDecodeError as e:
log.log_error(f"{file.name} is not a valid UTF8 file!")
log.log_debug(f"Exception: {e}")
log.log_error(f"Exception: {e}")
return None
except OSError as e:
log.log_error(f"{file.name} could not be read!")
log.log_debug(f"Exception: {e}")
log.log_error(f"Exception: {e}")
return None
return data
def create_container_from_config(data: dict, log: Log) -> Container | None:
"""Create a container object."""
log.log_info("Creating container...")
log.log_debug(f"Container config is:\n{data}")
ct: Container | None = None
try:
ct = Container(data)
@ -82,10 +80,8 @@ def main() -> None:
if data is None:
logger.log_error(f"{config_file} is invalid, aborting!")
sys.exit(1)
try:
ct = create_container_from_config(data, logger)
except ConfigError as e:
logger.log_error(e)
if ct is None:
sys.exit(1)
scripts = {
"create-volumes": ct.create_volumes,

View file

@ -8,21 +8,11 @@
import datetime
from pathlib import Path
from typing import TypeAlias
UNKNOWN = -1
ERROR = 0
WARNING = 1
INFO = 2
DEBUG = 3
LogLevel: TypeAlias = int
class Log:
"""Class for Logging."""
level: LogLevel = ERROR
messages: list = []
logfile: Path
@ -34,7 +24,6 @@ class Log:
def log_error(self, msg: str) -> None:
"""Log an error."""
if self.level >= ERROR:
now = self.timestamp()
prefix = "EE"
log_message = f"[{now}] ({prefix}) {msg}"
@ -42,28 +31,11 @@ class Log:
def log_warning(self, msg: str) -> None:
"""Log a warning."""
if self.level >= WARNING:
now = self.timestamp()
prefix = "WW"
log_message = f"[{now}] ({prefix}) {msg}"
self.write_message(log_message)
def log_info(self, msg: str) -> None:
"""Log an information."""
if self.level >= INFO:
now = self.timestamp()
prefix = "II"
log_message = f"[{now}] ({prefix}) {msg}"
self.write_message(log_message)
def log_debug(self, msg: str) -> None:
"""Log a debug message."""
if self.level >= DEBUG:
now = self.timestamp()
prefix = "DD"
log_message = f"[{now}] ({prefix}) {msg}"
self.write_message(log_message)
def write_message(self, msg: str) -> None:
"""Write the message."""
print(msg)