-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetfails.py
executable file
·103 lines (94 loc) · 3.26 KB
/
getfails.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#!/usr/bin/python3
import datetime
import json
import koji
import os
import requests
import rpm
WORK_DIR = os.getcwd()+"/"
TODAY = datetime.datetime.now().strftime('%Y-%m-%d')
JSON_URL = "http://distrobuildsync-eln-ops.apps.stream.rdu2.redhat.com/status.json"
OUTPUT_FILE = "failed-builds."+TODAY
OLD_FILE = "failed-builds.json"
TAG = "eln"
# Get our data
print("Getting current status")
status_data = {}
status_data = json.loads(requests.get(JSON_URL, allow_redirects=True).text)
#with open('status.json', 'r') as jsonfile:
# status_data = json.load(jsonfile)
old_data = {}
with open(OLD_FILE, 'r') as jsonfile:
old_data = json.load(jsonfile)
print("Getting latest builds")
latest_input = {}
koji_session = koji.ClientSession('https://koji.fedoraproject.org/kojihub')
latest_input = koji_session.listTagged(TAG, latest=True)
#with open('latest.json', 'r') as jsonfile:
# latest_input = json.load(jsonfile)
latest_builds = {}
for pkg in latest_input:
latest_builds[pkg['package_name']]=pkg['nvr']
## tmp testing helpers
#print(dir(status_data))
#print(status_data['bash'])
#print()
#print(dir(status_data['bash']))
#print(status_data['bash']['status'])
#with open('latest.json','w') as output:
# json.dump(latest_builds, output)
#print(latest_builds)
def rpm_compare(rpm1, rpm2):
try:
n1, v1, r1 = rpm1.rsplit('-', 2)
n2, v2, r2 = rpm2.rsplit('-', 2)
return rpm.labelCompare(('1', v1, r1), ('1', v2, r2))
except ValueError:
print("ERROR - bad names: " + rpm1 + " " + rpm2)
# Process data
print("Processing data")
checked_failures = {}
for json_entry in status_data:
try:
if status_data[json_entry]["status"] == "BuildStatus.FAILED":
failed = True
if json_entry in latest_builds:
latest_nvr = latest_builds[json_entry]
else:
latest_nvr = "unknown-0-0"
if '.fc3' in latest_nvr:
# print(json_entry + " " + status_data[json_entry]["status"] + " " + status_data[json_entry]["nvr"] + " " + latest_nvr)
#print(" FAIL - Rawhide package" + json_entry)
pass
else:
test_result = rpm_compare(latest_nvr, status_data[json_entry]["nvr"])
if test_result == 0:
failed = False
#print(" PASS - nvrs match " + json_entry)
elif test_result == 1:
failed = False
#print(" PASS - latest is newer " + json_entry)
elif test_result == -1:
#print(" FAIL - latest is older " + json_entry)
pass
else:
print(" ERROR - Something is wrong " + json_entry)
if failed:
this_failure = {}
this_failure['name'] = json_entry
this_failure['nvr'] = status_data[json_entry]["nvr"]
this_failure['view'] = status_data[json_entry]["view"]
this_failure['source'] = status_data[json_entry]["source"]
try:
this_failure['notes'] = old_data[json_entry]['notes']
except:
this_failure['notes'] = TODAY + " NEW"
print(" NEW " + json_entry)
checked_failures[json_entry] = this_failure
except TypeError:
pass
print("Total Failures: " + str(len(checked_failures)))
with open(OUTPUT_FILE, 'w') as output:
json.dump(checked_failures, output, indent=4, sort_keys=True)
# for sname in checked_failures:
# output.write("%s %s\n" % (sname, checked_failures[sname]))