parser.exit()
+def dict_with_capitalised_keys_factory(pairs: Any) -> dict[str, Any]:
+ def key_transformer(k: str) -> str:
+ if (s := SETTINGS_LOOKUP_BY_DEST.get(k)) is not None:
+ return s.name
+ return "".join(p.capitalize() for p in k.split("_"))
+
+ return {key_transformer(k): v for k, v in dict(pairs).items()}
+
+
@dataclasses.dataclass(frozen=True)
class Args:
verb: Verb
})
def to_dict(self) -> dict[str, Any]:
- def key_transformer(k: str) -> str:
- return "".join(p.capitalize() for p in k.split("_"))
-
- return {key_transformer(k): v for k, v in dataclasses.asdict(self).items()}
+ return dataclasses.asdict(self, dict_factory=dict_with_capitalised_keys_factory)
def to_json(self, *, indent: Optional[int] = 4, sort_keys: bool = True) -> str:
"""Dump MkosiArgs as JSON string."""
}
def to_dict(self) -> dict[str, Any]:
- def key_transformer(k: str) -> str:
- if (s := SETTINGS_LOOKUP_BY_DEST.get(k)) is not None:
- return s.name
- return "".join(p.capitalize() for p in k.split("_"))
-
- return {key_transformer(k): v for k, v in dataclasses.asdict(self).items()}
+ return dataclasses.asdict(self, dict_factory=dict_with_capitalised_keys_factory)
def to_json(self, *, indent: Optional[int] = 4, sort_keys: bool = True) -> str:
"""Dump MkosiConfig as JSON string."""
# TODO: exchange for TypeGuard and list comprehension once on 3.10
ret = []
for d in trees:
- assert "source" in d
- assert "target" in d
+ assert "Source" in d
+ assert "Target" in d
ret.append(
ConfigTree(
- source=Path(d["source"]),
- target=Path(d["target"]) if d["target"] is not None else None,
+ source=Path(d["Source"]),
+ target=Path(d["Target"]) if d["Target"] is not None else None,
)
)
return ret
# TODO: exchange for TypeGuard and list comprehension once on 3.10
ret = []
for d in drives:
- assert "id" in d
- assert "size" in d
- assert "directory" in d
- assert "options" in d
+ assert "Id" in d
+ assert "Size" in d
+ assert "Directory" in d
+ assert "Options" in d
ret.append(
QemuDrive(
- id=d["id"],
- size=int(d["size"]),
- directory=Path(d["directory"]) if d["directory"] else None,
- options=d["options"],
+ id=d["Id"],
+ size=int(d["Size"]),
+ directory=Path(d["Directory"]) if d["Directory"] else None,
+ options=d["Options"],
)
)
return ret
return GenericVersion(version) if version is not None else None
def key_source_transformer(keysource: dict[str, Any], fieldtype: type[KeySource]) -> KeySource:
- assert "type" in keysource
- return KeySource(type=KeySource.Type(keysource["type"]), source=keysource.get("source", ""))
+ assert "Type" in keysource
+ return KeySource(type=KeySource.Type(keysource["Type"]), source=keysource.get("Source", ""))
transformers = {
Path: path_transformer,
],
"BuildSources": [
{
- "source": "/qux",
- "target": "/frob"
+ "Source": "/qux",
+ "Target": "/frob"
}
],
"BuildSourcesEphemeral": true,
"PackageDirectories": [],
"PackageManagerTrees": [
{
- "source": "/foo/bar",
- "target": null
+ "Source": "/foo/bar",
+ "Target": null
}
],
"Packages": [],
"QemuCdrom": false,
"QemuDrives": [
{
- "directory": "/foo/bar",
- "id": "abc",
- "options": "abc,qed",
- "size": 200
+ "Directory": "/foo/bar",
+ "Id": "abc",
+ "Options": "abc,qed",
+ "Size": 200
},
{
- "directory": null,
- "id": "abc",
- "options": "",
- "size": 200
+ "Directory": null,
+ "Id": "abc",
+ "Options": "",
+ "Size": 200
}
],
"QemuFirmware": "linux",
"RuntimeSize": 8589934592,
"RuntimeTrees": [
{
- "source": "/foo/bar",
- "target": "/baz"
+ "Source": "/foo/bar",
+ "Target": "/baz"
},
{
- "source": "/bar/baz",
- "target": "/qux"
+ "Source": "/bar/baz",
+ "Target": "/qux"
}
],
"SELinuxRelabel": "disabled",
"SecureBootCertificate": null,
"SecureBootKey": "/path/to/keyfile",
"SecureBootKeySource": {
- "source": "",
- "type": "file"
+ "Source": "",
+ "Type": "file"
},
"SecureBootSignTool": "pesign",
"Seed": "7496d7d8-7f08-4a2b-96c6-ec8c43791b60",
"SignExpectedPcr": "disabled",
"SkeletonTrees": [
{
- "source": "/foo/bar",
- "target": "/"
+ "Source": "/foo/bar",
+ "Target": "/"
},
{
- "source": "/bar/baz",
- "target": "/qux"
+ "Source": "/bar/baz",
+ "Target": "/qux"
}
],
"SourceDateEpoch": 12345,
"ToolsTreeMirror": null,
"ToolsTreePackageManagerTrees": [
{
- "source": "/a/b/c",
- "target": "/"
+ "Source": "/a/b/c",
+ "Target": "/"
}
],
"ToolsTreePackages": [],
"VerityCertificate": "/path/to/cert",
"VerityKey": null,
"VerityKeySource": {
- "source": "",
- "type": "file"
+ "Source": "",
+ "Type": "file"
},
"VirtualMachineMonitor": "qemu",
"WithDocs": true,