Skip to content

Commit

Permalink
fix: [brctl] fixes library ID parsing without double quotes
Browse files Browse the repository at this point in the history
  • Loading branch information
dario-br committed Oct 7, 2024
1 parent 1531a88 commit c730255
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
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
41 changes: 24 additions & 17 deletions src/sysdiagnose/parsers/brctl.py
Original file line number Diff line number Diff line change
Expand Up @@ -328,30 +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(";", ",")
json_str1 = BrctlParser.parse_apps_monitor2json(parts[1].strip())
json_str2 = BrctlParser.parse_apps_monitor2json(parts[2].strip())

# ugly fixes
last_comma_index = json_str1.rfind(",")
json_str1_new = json_str1[:last_comma_index] + json_str1[last_comma_index + 1:]
# Load the JSON strings into Python dictionaries
json1 = json.loads(json_str1)
json2 = json.loads(json_str2)

return json1, json2

first_brace_index = json_str1_new.find("}")
json_str1 = json_str1_new[:first_brace_index + 1]
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 App IDs
json_str = re.sub(r'([\w\.]+)', r'"\1"', json_str)

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

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

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

return json1, json2

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

0 comments on commit c730255

Please sign in to comment.