-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscrapeThePatchJSON-testforregex-advanced.py
More file actions
50 lines (40 loc) · 1.5 KB
/
scrapeThePatchJSON-testforregex-advanced.py
File metadata and controls
50 lines (40 loc) · 1.5 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
44
45
46
47
48
49
import csv
import json
import re
import sys
# Check if the pattern arguments are provided
if len(sys.argv) < 3:
print("Usage: python script.py pattern_start pattern_end")
sys.exit(1)
# Retrieve the command-line arguments
name = sys.argv[1]
version = sys.argv[2]
old_version = sys.argv[3]
arch = sys.argv[4]
# Specify the path to the JSON file
json_file_path = "/tmp/temp-patchlistinfo.json"
# Read the JSON data from the file
with open(json_file_path, "r") as file:
json_data = file.read()
# Parse the JSON data
data = json.loads(json_data)
# Specify the path to the CSV file
csv_file_path = "/tmp/errata.csv"
# Open the CSV file for writing
with open(csv_file_path, "a", newline="") as csv_file:
writer = csv.writer(csv_file)
# Write the CSV header
#writer.writerow(["Update", "Severity", "Category"])
# Iterate through the data to find the matching entry and write it to the CSV file
for entry in data:
conflicts = entry.get("Conflicts", [])
for conflict in conflicts:
if re.search(f"{re.escape(name)}.* < {re.escape(version)}", conflict):
severity = entry.get("Severity")
category = entry.get("Category")
restart = entry.get("Interactive")
writer.writerow([name, version, old_version, severity, category, restart, arch])
break # Exit the loop after finding the matching entry
else:
continue
break # Exit the outer loop after finding the matching entry