1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-06-21 00:19:42 +02:00

working hub_port_status section

This commit is contained in:
Kelly Brazil
2021-10-22 10:31:26 -07:00
parent 159d87c112
commit 0e6f938514

View File

@ -17,6 +17,8 @@ Usage (module):
Schema: Schema:
Note: <attribute> field keynames are assigned directly from the lsusb output
[ [
{ {
"bus": string, "bus": string,
@ -24,12 +26,12 @@ Schema:
"id": string, "id": string,
"description": string, "description": string,
"device_descriptor": { "device_descriptor": {
"attribute": { "<attribute>": {
"value": string, "value": string,
"description": string "description": string
}, },
"configuration_descriptor": { "configuration_descriptor": {
"attribute": { "<attribute>": {
"value": string, "value": string,
"description": string "description": string
}, },
@ -39,37 +41,37 @@ Schema:
}, },
"interface_descriptors": [ "interface_descriptors": [
{ {
"attribute": { "<attribute>": {
"value": string, "value": string,
"description": string "description": string
}, },
"cdc_header": { "cdc_header": {
"attribute": { "<attribute>": {
"value": string, "value": string,
"description": string "description": string
} }
}, },
"cdc_call_management": { "cdc_call_management": {
"attribute": { "<attribute>": {
"value": string, "value": string,
"description": string "description": string
} }
}, },
"cdc_acm": { "cdc_acm": {
"attribute": { "<attribute>": {
"value": string, "value": string,
"description": string "description": string
} }
}, },
"cdc_union": { "cdc_union": {
"attribute": { "<attribute>": {
"value": string, "value": string,
"description": string "description": string
} }
}, },
"endpoint_descriptors": [ "endpoint_descriptors": [
{ {
"attribute": { "<attribute>": {
"value": string, "value": string,
"description": string "description": string
} }
@ -80,14 +82,16 @@ Schema:
} }
}, },
"hub_descriptor": { "hub_descriptor": {
"attribute": { "<attribute>": {
"value": string, "value": string,
"description": string "description": string
}, },
"hub_port_status": { "hub_port_status": {
"attribute": { "<attribute>": {
"value": string, "value": string,
"description": string "attributes": [
string
]
} }
} }
}, },
@ -194,6 +198,7 @@ class _LsUsb():
break break
return indent return indent
def _add_attributes(self, line): def _add_attributes(self, line):
indent = self._count_indent(line) indent = self._count_indent(line)
# Section header is formatted with the correct spacing to be used with # Section header is formatted with the correct spacing to be used with
@ -225,21 +230,25 @@ class _LsUsb():
return line_obj return line_obj
def _add_hub_port_status_attributes(self, line): def _add_hub_port_status_attributes(self, line):
return self._add_attributes(line) # Port 1: 0000.0103 power enable connect
# indent = self._count_indent(line) first_split = line.split(': ', maxsplit=1)
# line_obj = { port_field = first_split[0].strip()
# temp_obj['key']: { second_split = first_split[1].split(maxsplit=1)
# 'value': temp_obj['val'], port_val = second_split[0]
# 'description': temp_obj['description'], attributes = second_split[1].split()
# '_state': {
# 'indent': indent, return {
# 'bus_idx': self.bus_idx, port_field: {
# 'interface_descriptor_idx': self.interface_descriptor_idx, 'value': port_val,
# 'endpoint_descriptor_idx': self.endpoint_descriptor_idx 'attributes': attributes,
# } '_state': {
# } 'bus_idx': self.bus_idx
# } }
}
}
def _add_device_status_attributes(self, line): def _add_device_status_attributes(self, line):
return { return {
@ -323,6 +332,7 @@ class _LsUsb():
self.section = string_section_map[sec] self.section = string_section_map[sec]
return True return True
def _populate_lists(self, line): def _populate_lists(self, line):
section_list_map = { section_list_map = {
'device_descriptor': self.device_descriptor_list, 'device_descriptor': self.device_descriptor_list,
@ -353,6 +363,7 @@ class _LsUsb():
self.device_status_list.append(self._add_device_status_attributes(line)) self.device_status_list.append(self._add_device_status_attributes(line))
return True return True
def _populate_schema(self): def _populate_schema(self):
""" """
Schema: Schema:
@ -502,7 +513,6 @@ class _LsUsb():
del self.output_line['hub_descriptor']['hub_port_status'][keyname]['_state'] del self.output_line['hub_descriptor']['hub_port_status'][keyname]['_state']
for ds in self.device_status_list: for ds in self.device_status_list:
keyname = tuple(ds.keys())[0]
if '_state' in ds and ds['_state']['bus_idx'] == idx: if '_state' in ds and ds['_state']['bus_idx'] == idx:
self.output_line['device_status'].update(ds) self.output_line['device_status'].update(ds)
del self.output_line['device_status']['_state'] del self.output_line['device_status']['_state']
@ -544,23 +554,4 @@ def parse(data, raw=False, quiet=False):
if s.output_line: if s.output_line:
s.raw_output.append(s.output_line) s.raw_output.append(s.output_line)
# print(f'''
# {s.section=}
# {s.bus_list=}
# {s.device_descriptor_list=}
# {s.configuration_descriptor_list=}
# {s.interface_association_list=}
# {s.interface_descriptor_list=}
# {s.cdc_header_list=}
# {s.cdc_call_management_list=}
# {s.cdc_acm_list=}
# {s.cdc_union_list=}
# {s.endpoint_descriptor_list=}
# {s.hid_device_descriptor_list=}
# {s.report_descriptors_list=}
# {s.hub_descriptor_list=}
# {s.hub_port_status_list=}
# {s.device_status_list=}
# ''')
return s.raw_output if raw else _process(s.raw_output) return s.raw_output if raw else _process(s.raw_output)