From fd5433ee6220357e59633c78b689aa432d056b43 Mon Sep 17 00:00:00 2001 From: Kelly Brazil Date: Tue, 25 Jan 2022 18:58:09 -0800 Subject: [PATCH] parse docstring formatting --- docs/lib.md | 4 +- docs/parsers/lsusb.md | 291 ------------------------------------------ jc/lib.py | 4 +- 3 files changed, 6 insertions(+), 293 deletions(-) diff --git a/docs/lib.md b/docs/lib.md index d6b26f72..ef1d9dcb 100644 --- a/docs/lib.md +++ b/docs/lib.md @@ -10,7 +10,9 @@ JC lib module #### parse ```python -def parse(parser_mod_name: str, data: Union[str, Iterable[str]], quiet: Optional[bool] = False, raw: Optional[bool] = False, ignore_exceptions: Optional[Union[None, bool]] = None, **kwargs: Any, ,) -> Union[Dict[str, Any], List[Dict[str, Any]], Iterator[Dict[str, Any]]] +def parse(parser_mod_name: str, data: Union[str, Iterable[str]], quiet: Optional[bool] = False, raw: Optional[bool] = False, ignore_exceptions: Optional[Union[None, bool]] = None, **kwargs: Any, ,) -> Union[Dict[str, Any], + List[Dict[str, Any]], + Iterator[Dict[str, Any]]] ``` Parse the string data using the supplied parser module. diff --git a/docs/parsers/lsusb.md b/docs/parsers/lsusb.md index ed5e4822..10ddb0a0 100644 --- a/docs/parsers/lsusb.md +++ b/docs/parsers/lsusb.md @@ -1,292 +1 @@ [Home](https://kellyjonbrazil.github.io/jc/) - - -# jc.parsers.lsusb - -jc - JSON CLI output utility `lsusb` command output parser - -Supports the `-v` option or no options. - -Usage (cli): - - $ lsusb -v | jc --lsusb - - or - - $ jc lsusb -v - -Usage (module): - - import jc - result = jc.parse('lsusb', lsusb_command_output) - - or - - import jc.parsers.lsusb - result = jc.parsers.lsusb.parse(lsusb_command_output) - -Schema: - - Note: object keynames are assigned directly from the lsusb - output. If there are duplicate names in a section, only the - last one is converted. - - [ - { - "bus": string, - "device": string, - "id": string, - "description": string, - "device_descriptor": { - "": { - "value": string, - "description": string, - "attributes": [ - string - ] - }, - "configuration_descriptor": { - "": { - "value": string, - "description": string, - "attributes": [ - string - ] - }, - "interface_association": { - "": { - "value": string, - "description": string, - "attributes": [ - string - ] - } - }, - "interface_descriptors": [ - { - "": { - "value": string, - "description": string, - "attributes": [ - string - ] - }, - "cdc_header": { - "": { - "value": string, - "description": string, - "attributes": [ - string - ] - } - }, - "cdc_call_management": { - "": { - "value": string, - "description": string, - "attributes": [ - string - ] - } - }, - "cdc_acm": { - "": { - "value": string, - "description": string, - "attributes": [ - string - ] - } - }, - "cdc_union": { - "": { - "value": string, - "description": string, - "attributes": [ - string - ] - } - }, - "endpoint_descriptors": [ - { - "": { - "value": string, - "description": string, - "attributes": [ - string - ] - } - } - ] - } - ] - } - }, - "hub_descriptor": { - "": { - "value": string, - "description": string, - "attributes": [ - string, - ] - }, - "hub_port_status": { - "": { - "value": string, - "attributes": [ - string - ] - } - } - }, - "device_status": { - "value": string, - "description": string - } - } - ] - -Examples: - - $ lsusb -v | jc --lsusb -p - [ - { - "bus": "002", - "device": "001", - "id": "1d6b:0001", - "description": "Linux Foundation 1.1 root hub", - "device_descriptor": { - "bLength": { - "value": "18" - }, - "bDescriptorType": { - "value": "1" - }, - "bcdUSB": { - "value": "1.10" - }, - ... - "bNumConfigurations": { - "value": "1" - }, - "configuration_descriptor": { - "bLength": { - "value": "9" - }, - ... - "iConfiguration": { - "value": "0" - }, - "bmAttributes": { - "value": "0xe0", - "attributes": [ - "Self Powered", - "Remote Wakeup" - ] - }, - "MaxPower": { - "description": "0mA" - }, - "interface_descriptors": [ - { - "bLength": { - "value": "9" - }, - ... - "bInterfaceProtocol": { - "value": "0", - "description": "Full speed (or root) hub" - }, - "iInterface": { - "value": "0" - }, - "endpoint_descriptors": [ - { - "bLength": { - "value": "7" - }, - ... - "bmAttributes": { - "value": "3", - "attributes": [ - "Transfer Type Interrupt", - "Synch Type None", - "Usage Type Data" - ] - }, - "wMaxPacketSize": { - "value": "0x0002", - "description": "1x 2 bytes" - }, - "bInterval": { - "value": "255" - } - } - ] - } - ] - } - }, - "hub_descriptor": { - "bLength": { - "value": "9" - }, - ... - "wHubCharacteristic": { - "value": "0x000a", - "attributes": [ - "No power switching (usb 1.0)", - "Per-port overcurrent protection" - ] - }, - ... - "hub_port_status": { - "Port 1": { - "value": "0000.0103", - "attributes": [ - "power", - "enable", - "connect" - ] - }, - "Port 2": { - "value": "0000.0103", - "attributes": [ - "power", - "enable", - "connect" - ] - } - } - }, - "device_status": { - "value": "0x0001", - "description": "Self Powered" - } - } - ] - - - -#### parse - -```python -def parse(data, raw=False, quiet=False) -``` - -Main text parsing function - -Parameters: - - data: (string) text data to parse - raw: (boolean) unprocessed output if True - quiet: (boolean) suppress warning messages if True - -Returns: - - List of Dictionaries. Raw or processed structured data. - -#### Parser Information -Compatibility: linux - -Version 1.1 by Kelly Brazil (kellyjonbrazil@gmail.com) diff --git a/jc/lib.py b/jc/lib.py index 283b711b..1d7babd9 100644 --- a/jc/lib.py +++ b/jc/lib.py @@ -146,7 +146,9 @@ def parse(parser_mod_name: str, raw: Optional[bool] = False, ignore_exceptions: Optional[Union[None, bool]] = None, **kwargs: Any, - ) -> Union[Dict[str, Any], List[Dict[str, Any]], Iterator[Dict[str, Any]]]: + ) -> Union[Dict[str, Any], + List[Dict[str, Any]], + Iterator[Dict[str, Any]]]: """ Parse the string data using the supplied parser module.