1
0
mirror of https://github.com/kellyjonbrazil/jc.git synced 2025-08-06 22:32:54 +02:00

simplify fixup logic for uname

This commit is contained in:
Kelly Brazil
2021-10-20 15:27:14 -07:00
parent 2b2123a4ba
commit 92bf2b1ca2
2 changed files with 8 additions and 20 deletions

View File

@ -2,7 +2,7 @@ jc changelog
20211019 v1.17.1 *** in progress ***
- Fix file parser for gzip files
- Fix uname parser for cases where the 'processor' and/or 'machine' fields are missing on linux
- Fix uname parser for cases where the 'processor' and/or 'hardware_platform' fields are missing on linux
- Fix uname parser on FreeBSD
- Add lsusb parser tested on linux

View File

@ -113,25 +113,13 @@ def parse(data, raw=False, quiet=False):
# otherwise use linux parser
else:
# fixup for cases where the 'processor' and/or 'machine' fields are blank
fixup_count = 0
# fixup for cases where the 'processor' and/or 'hardware_platform' fields are blank
fixup = data.split()
cleanup = True
if fixup[-2] == fixup[-3] and fixup[-2] != fixup[-4]:
fixup_count = 1
elif fixup[-2] != fixup[-3]:
fixup_count = 2
else:
cleanup = False
if cleanup:
for item in range(fixup_count):
fixup.insert(-2, 'unknown')
fixup_set = set([fixup[-2], fixup[-3], fixup[-4]])
if len(fixup_set) > 2:
fixup.insert(-1, 'unknown')
fixup.insert(-1, 'unknown')
data = ' '.join(fixup)
# end fixup
parsed_line = data.split(maxsplit=3)
@ -145,8 +133,8 @@ def parse(data, raw=False, quiet=False):
parsed_line = parsed_line[-1].rsplit(maxsplit=4)
raw_output['operating_system'] = parsed_line.pop(-1)
raw_output['hardware_platform'] = parsed_line.pop(-1)
raw_output['processor'] = parsed_line.pop(-1)
raw_output['hardware_platform'] = parsed_line.pop(-1)
raw_output['machine'] = parsed_line.pop(-1)
raw_output['kernel_version'] = parsed_line.pop(0)