From 1ac7a724bdf1bb6cd4d5711d209fb5747b18a255 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Fri, 21 Oct 2022 12:45:19 -0700 Subject: [PATCH] integer conversions --- docs/parsers/lspci.md | 4 +++- jc/parsers/lspci.py | 24 ++++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/docs/parsers/lspci.md b/docs/parsers/lspci.md index 80a61d23..1d982bd8 100644 --- a/docs/parsers/lspci.md +++ b/docs/parsers/lspci.md @@ -46,7 +46,9 @@ Examples: ### parse ```python -def parse(data: str, raw: bool = False, quiet: bool = False) -> List[Dict] +def parse(data: str, + raw: bool = False, + quiet: bool = False) -> List[JSONDictType] ``` Main text parsing function diff --git a/jc/parsers/lspci.py b/jc/parsers/lspci.py index 713939e4..d8a9748c 100644 --- a/jc/parsers/lspci.py +++ b/jc/parsers/lspci.py @@ -38,6 +38,7 @@ Examples: """ import re from typing import List, Dict +from jc.jc_types import JSONDictType import jc.utils @@ -54,7 +55,7 @@ class info(): __version__ = info.version -def _process(proc_data: List[Dict]) -> List[Dict]: +def _process(proc_data: List[JSONDictType]) -> List[JSONDictType]: """ Final processing to conform to the schema. @@ -66,14 +67,29 @@ def _process(proc_data: List[Dict]) -> List[Dict]: List of Dictionaries. Structured to conform to the schema. """ - return proc_data + int_list: set[str] = { + 'domain', 'bus', 'dev', 'function', 'class_id', 'vendor_id', 'device_id', + 'svendor_id', 'sdevice_id', 'physlot', 'progif' + } + + new_list: List[JSONDictType] = [] + + for item in proc_data: + output: Dict = {} + for key, val in item.items(): + output[key] = val + if key in int_list: + output[key + '_int'] = int(val, 16) # type: ignore + new_list.append(output) + + return new_list def parse( data: str, raw: bool = False, quiet: bool = False -) -> List[Dict]: +) -> List[JSONDictType]: """ Main text parsing function @@ -111,7 +127,7 @@ def parse( if domain: dom = domain[0] else: - dom = None + dom = "00" dev, fun = dev_fun.split('.') device_output['domain'] = dom