Add system method to Quasar model and update TTP template
- Implemented a new `system` method in the `Quasar` model to extract and format system information, including version handling. - Updated the TTP template to adjust the grouping and ignore patterns for better parsing of system details, ensuring compatibility with the new method.
This commit is contained in:
@@ -5,6 +5,23 @@ from oxi.interfaces import BaseDevice, register_parser
|
||||
class Quasar(BaseDevice):
|
||||
template = "quasar.ttp"
|
||||
|
||||
def system(self) -> dict:
|
||||
raw = self.raw.get("system", {})
|
||||
items = raw if isinstance(raw, list) else [raw]
|
||||
selected = next(
|
||||
(item for item in items if item.get("assembly_version")),
|
||||
items[0] if items else {},
|
||||
)
|
||||
result = dict(selected)
|
||||
result["version"] = (
|
||||
result.pop("assembly_version", None)
|
||||
or result.pop("engine_version", None)
|
||||
or ""
|
||||
)
|
||||
result.pop("assembly_version", None)
|
||||
result.pop("engine_version", None)
|
||||
return result
|
||||
|
||||
def interfaces(self) -> list[dict]:
|
||||
ether_interfaces: dict = self.raw["interfaces"]
|
||||
interfaces: list[dict] = []
|
||||
@@ -28,3 +45,9 @@ if __name__ == "__main__":
|
||||
quasar = Quasar(data)
|
||||
qt = quasar.parse()
|
||||
print(qt)
|
||||
print()
|
||||
with open("./test8.txt") as file:
|
||||
data = file.read()
|
||||
quasar = Quasar(data)
|
||||
qt = quasar.parse()
|
||||
print(qt)
|
||||
|
||||
Reference in New Issue
Block a user