1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-07-15 01:24:29 +02:00

formatting

This commit is contained in:
Kelly Brazil
2023-01-06 08:26:42 -08:00
parent 61bdc13810
commit d1b270f336
2 changed files with 15 additions and 25 deletions

View File

@ -341,6 +341,7 @@ class _root_obj:
if '_state' in item[keyname] and item[keyname]['_state']['bus_idx'] == bus_idx: if '_state' in item[keyname] and item[keyname]['_state']['bus_idx'] == bus_idx:
return True return True
return False return False
def _update_output(self, bus_idx, output_line): def _update_output(self, bus_idx, output_line):
@ -370,7 +371,8 @@ class _descriptor_obj:
self.list = [] self.list = []
def _entries_for_this_bus_and_interface_idx_exist(self, bus_idx, iface_idx): def _entries_for_this_bus_and_interface_idx_exist(self, bus_idx, iface_idx):
"""Returns true if there are object entries for the corresponding bus index and interface index""" """Returns true if there are object entries for the corresponding bus index
and interface index"""
for item in self.list: for item in self.list:
keyname = tuple(item.keys())[0] keyname = tuple(item.keys())[0]
@ -378,11 +380,12 @@ class _descriptor_obj:
and item[keyname]['_state']['interface_descriptor_idx'] == iface_idx: and item[keyname]['_state']['interface_descriptor_idx'] == iface_idx:
return True return True
return False return False
def _update_output(self, bus_idx, iface_idx, output_line): def _update_output(self, bus_idx, iface_idx, output_line):
"""modifies output_line dictionary for the corresponding bus index and interface index. """modifies output_line dictionary for the corresponding bus index and
output_line is the i_desc_obj object.""" interface index. output_line is the i_desc_obj object."""
for item in self.list: for item in self.list:
keyname = tuple(item.keys())[0] keyname = tuple(item.keys())[0]
@ -409,7 +412,8 @@ class _descriptor_list:
self.list = [] self.list = []
def _entries_for_this_bus_and_interface_idx_exist(self, bus_idx, iface_idx): def _entries_for_this_bus_and_interface_idx_exist(self, bus_idx, iface_idx):
"""Returns true if there are object entries for the corresponding bus index and interface index""" """Returns true if there are object entries for the corresponding bus index
and interface index"""
for item in self.list: for item in self.list:
keyname = tuple(item.keys())[0] keyname = tuple(item.keys())[0]
@ -417,10 +421,12 @@ class _descriptor_list:
and item[keyname]['_state']['interface_descriptor_idx'] == iface_idx: and item[keyname]['_state']['interface_descriptor_idx'] == iface_idx:
return True return True
return False return False
def _get_objects_list(self, bus_idx, iface_idx): def _get_objects_list(self, bus_idx, iface_idx):
"""Returns a list of descriptor object dictionaries for the corresponding bus index and interface index""" """Returns a list of descriptor object dictionaries for the corresponding
bus index and interface index"""
object_collection = [] object_collection = []
# find max number of items in this object that match the bus_idx and iface_idx # find max number of items in this object that match the bus_idx and iface_idx
@ -458,6 +464,7 @@ class _descriptor_list:
del item[keyname]['_state'] del item[keyname]['_state']
object_collection.append(this_object) object_collection.append(this_object)
return object_collection return object_collection
@ -812,7 +819,6 @@ class _LsUsb():
for iface_idx in range(i_desc_iters + 1): for iface_idx in range(i_desc_iters + 1):
i_desc_obj = _NestedDict() i_desc_obj = _NestedDict()
## interface_descriptor_list _root object?
for iface_attrs in self.interface_descriptor_list: for iface_attrs in self.interface_descriptor_list:
keyname = tuple(iface_attrs.keys())[0] keyname = tuple(iface_attrs.keys())[0]
@ -834,28 +840,19 @@ class _LsUsb():
del iface_attrs[keyname]['_state'] del iface_attrs[keyname]['_state']
i_desc_obj.update(iface_attrs) i_desc_obj.update(iface_attrs)
# add cdc_header key if it doesn't exist and there are # add the rest of the interface descriptor keys to the object
# entries for this interface_descriptor
if self.cdc_header._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx): if self.cdc_header._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx):
self.cdc_header._update_output(idx, iface_idx, i_desc_obj) self.cdc_header._update_output(idx, iface_idx, i_desc_obj)
# add cdc_call_management key if it doesn't exist and there are
# entries for this interface_descriptor
if self.cdc_call_management._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx): if self.cdc_call_management._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx):
self.cdc_call_management._update_output(idx, iface_idx, i_desc_obj) self.cdc_call_management._update_output(idx, iface_idx, i_desc_obj)
# add cdc_acm key if it doesn't exist and there are entries for
# this interface_descriptor
if self.cdc_acm._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx): if self.cdc_acm._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx):
self.cdc_acm._update_output(idx, iface_idx, i_desc_obj) self.cdc_acm._update_output(idx, iface_idx, i_desc_obj)
# add cdc_union key if it doesn't exist and there are entries for
# this interface_descriptor
if self.cdc_union._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx): if self.cdc_union._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx):
self.cdc_union._update_output(idx, iface_idx, i_desc_obj) self.cdc_union._update_output(idx, iface_idx, i_desc_obj)
# add hid_device_descriptor key if it doesn't exist and there are
# entries for this interface_descriptor
if self.hid_device_descriptor._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx): if self.hid_device_descriptor._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx):
self.hid_device_descriptor._update_output(idx, iface_idx, i_desc_obj) self.hid_device_descriptor._update_output(idx, iface_idx, i_desc_obj)
@ -866,24 +863,18 @@ class _LsUsb():
# i_desc_obj['hid_device_descriptor']['report_descriptors'].update(rd) # i_desc_obj['hid_device_descriptor']['report_descriptors'].update(rd)
# del i_desc_obj['hid_device_descriptor']['report_descriptors'][keyname]['_state'] # del i_desc_obj['hid_device_descriptor']['report_descriptors'][keyname]['_state']
# add videocontrol_interface_descriptors key if it doesn't exist
# and there are entries for this interface_descriptor
if self.videocontrol_interface_descriptors._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx): if self.videocontrol_interface_descriptors._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx):
i_desc_obj['videocontrol_interface_descriptors'] = [] i_desc_obj['videocontrol_interface_descriptors'] = []
i_desc_obj['videocontrol_interface_descriptors'].extend( i_desc_obj['videocontrol_interface_descriptors'].extend(
self.videocontrol_interface_descriptors._get_objects_list(idx, iface_idx) self.videocontrol_interface_descriptors._get_objects_list(idx, iface_idx)
) )
# add videostreaming_interface_descriptors key if it doesn't exist
# and there are entries for this interface_descriptor
if self.videostreaming_interface_descriptors._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx): if self.videostreaming_interface_descriptors._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx):
i_desc_obj['videostreaming_interface_descriptors'] = [] i_desc_obj['videostreaming_interface_descriptors'] = []
i_desc_obj['videostreaming_interface_descriptors'].extend( i_desc_obj['videostreaming_interface_descriptors'].extend(
self.videostreaming_interface_descriptors._get_objects_list(idx, iface_idx) self.videostreaming_interface_descriptors._get_objects_list(idx, iface_idx)
) )
# add endpoint_descriptors key if it doesn't exist and there are
# entries for this interface_descriptor
if self.endpoint_descriptors._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx): if self.endpoint_descriptors._entries_for_this_bus_and_interface_idx_exist(idx, iface_idx):
i_desc_obj['endpoint_descriptors'] = [] i_desc_obj['endpoint_descriptors'] = []
i_desc_obj['endpoint_descriptors'].extend( i_desc_obj['endpoint_descriptors'].extend(
@ -893,8 +884,7 @@ class _LsUsb():
# add the object to the list of interface descriptors # add the object to the list of interface descriptors
self.output_line['device_descriptor']['configuration_descriptor']['interface_descriptors'].append(i_desc_obj) self.output_line['device_descriptor']['configuration_descriptor']['interface_descriptors'].append(i_desc_obj)
# add hub_descriptor key if it doesn't exist and there are # add final root-level keys
# entries for this interface_descriptor
if self.hub_descriptor._entries_for_this_bus_exist(idx): if self.hub_descriptor._entries_for_this_bus_exist(idx):
self.hub_descriptor._update_output(idx, self.output_line) self.hub_descriptor._update_output(idx, self.output_line)

View File

@ -1,4 +1,4 @@
.TH jc 1 2023-01-05 1.22.5 "JSON Convert" .TH jc 1 2023-01-06 1.22.5 "JSON Convert"
.SH NAME .SH NAME
\fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types, and strings \fBjc\fP \- JSON Convert JSONifies the output of many CLI tools, file-types, and strings
.SH SYNOPSIS .SH SYNOPSIS