Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [brctl] fixes library ID parsing without double quotes #104

Merged
merged 4 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,14 @@
"args": "-c public parse demo_parser",
"cwd": "${workspaceFolder}/"
},
{
"name": "Python Debugger: parse brctl",
"type": "debugpy",
"request": "launch",
"module": "sysdiagnose.main",
"args": "-c public parse brctl",
"cwd": "${workspaceFolder}/"
},
{
"name": "Python Debugger: parse logarchive",
"type": "debugpy",
Expand Down
42 changes: 24 additions & 18 deletions src/sysdiagnose/parsers/brctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,31 +328,37 @@ def parse_apps_monitor(data):
parts = data.split("=======================")

# Extract the JSON strings from each part
json_str1 = parts[1].strip().replace("=", ":").replace("\\", "").replace(
"\"{(n \"", "[\"").replace("\"n)}\"", "\"]").replace(",n ", ",").replace(";", ",")
json_str2 = parts[2].strip().replace("=", ":").replace("\\", "").replace(
"\"{(n \"", "[\"").replace("\"n)}\"", "\"]").replace(",n ", ",").replace(";", ",")

# ugly fixes
last_comma_index = json_str1.rfind(",")
json_str1_new = json_str1[:last_comma_index] + json_str1[last_comma_index + 1:]

first_brace_index = json_str1_new.find("}")
json_str1 = json_str1_new[:first_brace_index + 1]

# ugly fixes
last_comma_index = json_str2.rfind(",")
json_str2_new = json_str2[:last_comma_index] + json_str2[last_comma_index + 1:]

first_brace_index = json_str2_new.find("}")
json_str2 = json_str2_new[:first_brace_index + 1]
json_str1 = BrctlParser.__parse_apps_monitor2json(parts[1].strip())
json_str2 = BrctlParser.__parse_apps_monitor2json(parts[2].strip())

# Load the JSON strings into Python dictionaries
json1 = json.loads(json_str1)
json2 = json.loads(json_str2)

return json1, json2

def __parse_apps_monitor2json(data):
# replace = by :
json_str = data.replace("=", ":")
# remove literal string '\n'
json_str = re.sub(r'\\n\s*', '', json_str)
# remove char \
# replace start of array string representation "{( by [
# replace end of array string representation )}" by ]
# remove char "
json_str = json_str.replace("\\", "").replace('"{(', '[').replace(')}";', '],').replace('"', '')
# adds double quotes to all bundle IDs or library IDs
json_str = re.sub(r'([\w\.\-]+)', r'"\1"', json_str)

# ugly fixes
last_comma_index = json_str.rfind(",")
json_str_new = json_str[:last_comma_index] + json_str[last_comma_index + 1:]

first_brace_index = json_str_new.find("}")
json_str = json_str_new[:first_brace_index + 1]

return json_str

def parse_folder(brctl_folder):
container_list_file = [os.path.join(brctl_folder, 'brctl-container-list.txt')]
container_dump_file = [os.path.join(brctl_folder, 'brctl-dump.txt')]
Expand Down
Loading