diff --git a/src/gallia/command/base.py b/src/gallia/command/base.py index 5f36191c4..7363d1907 100644 --- a/src/gallia/command/base.py +++ b/src/gallia/command/base.py @@ -31,7 +31,7 @@ from gallia.powersupply import PowerSupply, PowerSupplyURI from gallia.services.uds.core.exception import UDSException from gallia.transports import BaseTransport, TargetURI -from gallia.utils import camel_to_snake +from gallia.utils import camel_to_snake, dump_args @unique @@ -494,6 +494,8 @@ async def _db_insert_run_meta(self, args: Namespace) -> None: await self.db_handler.insert_run_meta( script=sys.argv[0].split()[-1], arguments=sys.argv[1:], + command_meta=msgspec.json.encode(self.run_meta.command_meta), + settings=dump_args(args), start_time=datetime.now(timezone.utc).astimezone(), path=self.artifacts_dir, ) diff --git a/src/gallia/db/handler.py b/src/gallia/db/handler.py index ef44c11d5..659e8ac7d 100644 --- a/src/gallia/db/handler.py +++ b/src/gallia/db/handler.py @@ -27,7 +27,7 @@ def bytes_repr(data: bytes) -> str: return bytes_repr_(data, False, None) -schema_version = "1.0" +schema_version = "2.0" DB_SCHEMA = f""" CREATE TABLE IF NOT EXISTS version ( @@ -50,6 +50,8 @@ def bytes_repr(data: bytes) -> str: id integer primary key, script text not null, arguments json not null check(json_valid(arguments)), + command_meta json not null check(json_valid(arguments)), + settings json not null check(json_valid(arguments)), start_time real not null, start_timezone text not null, end_time real, @@ -191,20 +193,28 @@ async def check_version(self) -> None: f"The version of the database schema is not supported! ({version} != {schema_version})" ) - async def insert_run_meta( - self, script: str, arguments: list[str], start_time: datetime, path: Path + async def insert_run_meta( # noqa: CODE + self, + script: str, + arguments: list[str], + command_meta: bytes, + settings: dict[str, str | int | float], + start_time: datetime, + path: Path, ) -> None: assert self.connection is not None, "Not connected to the database" query = ( - "INSERT INTO run_meta(script, arguments, start_time, start_timezone, path) VALUES " - "(?, ?, ?, ?, ?)" + "INSERT INTO run_meta(script, arguments, command_meta, settings, start_time, start_timezone, path) VALUES " + "(?, ?, ?, ?, ?, ?, ?)" ) cursor = await self.connection.execute( query, ( script, json.dumps(arguments), + command_meta, + json.dumps(settings), start_time.timestamp(), start_time.tzname(), str(path), diff --git a/src/gallia/utils.py b/src/gallia/utils.py index 84e62a2b2..f8775a550 100644 --- a/src/gallia/utils.py +++ b/src/gallia/utils.py @@ -212,3 +212,13 @@ def lazy_import(name: str) -> ModuleType: sys.modules[name] = module loader.exec_module(module) return module + + +def dump_args(args: Namespace) -> dict[str, str | int | float]: + settings = {} + for key, value in args.__dict__.items(): + match value: + case str() | int() | float(): + settings[key] = value + + return settings