mirror of
https://github.com/kellyjonbrazil/jc.git
synced 2025-07-17 01:32:37 +02:00
linting
This commit is contained in:
@ -294,7 +294,8 @@ class _NestedDict(dict):
|
||||
# https://stackoverflow.com/questions/5369723/multi-level-defaultdict-with-variable-depth
|
||||
# https://ohuiginn.net/mt/2010/07/nested_dictionaries_in_python.html
|
||||
def __getitem__(self, key):
|
||||
if key in self: return self.get(key)
|
||||
if key in self:
|
||||
return self.get(key)
|
||||
return self.setdefault(key, _NestedDict())
|
||||
|
||||
|
||||
@ -340,14 +341,13 @@ class _LsUsb():
|
||||
break
|
||||
return indent
|
||||
|
||||
|
||||
def _add_attributes(self, line):
|
||||
indent = self._count_indent(line)
|
||||
|
||||
# determine whether this is a top-level value item or lower-level attribute
|
||||
if indent > self.last_indent and self.old_section == self.section:
|
||||
self.attribute_value = True
|
||||
elif indent == self.last_indent and self.attribute_value == True and self.old_section == self.section:
|
||||
elif indent == self.last_indent and self.attribute_value and self.old_section == self.section:
|
||||
self.attribute_value = True
|
||||
else:
|
||||
self.attribute_value = False
|
||||
@ -388,7 +388,6 @@ class _LsUsb():
|
||||
|
||||
return line_obj
|
||||
|
||||
|
||||
def _add_hub_port_status_attributes(self, line):
|
||||
# Port 1: 0000.0103 power enable connect
|
||||
first_split = line.split(': ', maxsplit=1)
|
||||
@ -407,7 +406,6 @@ class _LsUsb():
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def _add_device_status_attributes(self, line):
|
||||
return {
|
||||
'description': line.strip(),
|
||||
@ -416,7 +414,6 @@ class _LsUsb():
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
def _set_sections(self, line):
|
||||
# ignore blank lines
|
||||
if not line:
|
||||
@ -496,7 +493,6 @@ class _LsUsb():
|
||||
self.attribute_value = False
|
||||
return True
|
||||
|
||||
|
||||
def _populate_lists(self, line):
|
||||
section_list_map = {
|
||||
'device_descriptor': self.device_descriptor_list,
|
||||
@ -527,7 +523,6 @@ class _LsUsb():
|
||||
self.device_status_list.append(self._add_device_status_attributes(line))
|
||||
return True
|
||||
|
||||
|
||||
def _populate_schema(self):
|
||||
"""
|
||||
Schema:
|
||||
@ -564,8 +559,8 @@ class _LsUsb():
|
||||
# is this a top level value or an attribute?
|
||||
if dd[keyname]['_state']['attribute_value']:
|
||||
last_item = dd[keyname]['_state']['last_item']
|
||||
if 'attributes' not in self.output_line['device_descriptor'][last_item]:
|
||||
self.output_line['device_descriptor'][last_item]['attributes'] = []
|
||||
if 'attributes' not in self.output_line['device_descriptor'][last_item]:
|
||||
self.output_line['device_descriptor'][last_item]['attributes'] = []
|
||||
|
||||
this_attribute = f'{keyname} {dd[keyname].get("value", "")} {dd[keyname].get("description", "")}'.strip()
|
||||
self.output_line['device_descriptor'][last_item]['attributes'].append(this_attribute)
|
||||
@ -581,8 +576,8 @@ class _LsUsb():
|
||||
# is this a top level value or an attribute?
|
||||
if cd[keyname]['_state']['attribute_value']:
|
||||
last_item = cd[keyname]['_state']['last_item']
|
||||
if 'attributes' not in self.output_line['device_descriptor']['configuration_descriptor'][last_item]:
|
||||
self.output_line['device_descriptor']['configuration_descriptor'][last_item]['attributes'] = []
|
||||
if 'attributes' not in self.output_line['device_descriptor']['configuration_descriptor'][last_item]:
|
||||
self.output_line['device_descriptor']['configuration_descriptor'][last_item]['attributes'] = []
|
||||
|
||||
this_attribute = f'{keyname} {cd[keyname].get("value", "")} {cd[keyname].get("description", "")}'.strip()
|
||||
self.output_line['device_descriptor']['configuration_descriptor'][last_item]['attributes'].append(this_attribute)
|
||||
@ -826,7 +821,7 @@ def parse(data, raw=False, quiet=False):
|
||||
for line in data.splitlines():
|
||||
# only -v option or no options are supported
|
||||
if line.startswith('/'):
|
||||
raise ParseError('Only `lsusb` or `lsusb -v` are supported.')
|
||||
raise ParseError('Only `lsusb` or `lsusb -v` are supported.')
|
||||
|
||||
# sections
|
||||
if lsusb._set_sections(line):
|
||||
|
Reference in New Issue
Block a user