-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTXT2JSON-ConverterForPatchInfo.py
More file actions
44 lines (32 loc) · 1.19 KB
/
TXT2JSON-ConverterForPatchInfo.py
File metadata and controls
44 lines (32 loc) · 1.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import json
file_path = '/tmp/temp-patchlistinfo.txt'
# Read the contents of the file
with open(file_path, 'r') as file:
data = file.read()
# Split the data into blocks
blocks = data.split('Information for patch')[1:]
# Create a list to store the parsed data for each block
parsed_blocks = []
# Iterate over the blocks and extract the information
for block in blocks:
lines = block.split('\n')
parsed_data = {}
conflicts_lines = []
is_conflicts_block = False
for line in lines:
if line.strip() != '':
if ':' in line:
key, value = line.split(':', 1)
parsed_data[key.strip()] = value.strip()
if line.strip().startswith('Conflicts'):
is_conflicts_block = True
parsed_data['Conflicts'] = line.split(':', 1)[1].strip().strip('[]')
elif is_conflicts_block and line.startswith(' '):
conflicts_lines.append(line.strip())
if conflicts_lines:
parsed_data['Conflicts'] = conflicts_lines
parsed_blocks.append(parsed_data)
# Convert the list of parsed blocks to JSON
json_data = json.dumps(parsed_blocks, indent=4)
# Print the JSON data
print(json_data)