-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtodo_generator.py
138 lines (115 loc) · 4.74 KB
/
todo_generator.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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
import configparser
import json
from copr.v3 import Client
import os
import sys
import io
import urllib
def load_config(file):
c = configparser.ConfigParser()
c.read(file)
return c
def create_copr_client(configfile = None, copr_url = None):
if copr_url:
config = {'copr_url' : copr_url }
return Client(config)
return Client.create_from_config_file(configfile)
def get_package(name, pkg_list):
for p in pkg_list:
if p['name'] == name:
return p
return None
def get_combined_build_state(chroots):
state = 'succeeded'
for c in chroots:
chroot = chroots[c]
if chroot['state'] == 'failed':
state = 'failed'
break
return state
def handle_missing_builds(builds_a, builds_b):
arches = set([])
for builds in [builds_a, builds_b]:
for build in builds:
arch = build.name.split('-')[-1]
if arch not in arches:
arches.add(arch)
for arch in arches:
for builds in [builds_a, builds_b]:
if not has_arch(builds, arch):
builds.append(create_missing_build(arch))
def add_url_build_log_field(project, packages):
for p in packages:
for c in p['chroots']:
chroot = p['chroots'][c]
chroot['url_build_log'] = "{}0{}-{}/builder-live.log{}".format(project['chroot_repos'][c], chroot['build_id'], p['name'],
".gz" if chroot['state'] != 'running' else "")
chroot['url_resubmit'] = 'https://copr.fedorainfracloud.org/coprs/g/{}/repeat_build/{}/'.format(project['full_name'][1:], chroot['build_id'])
def add_url_rebuild_field(project, packages):
for p in packages:
p['url_rebuild'] = "https://copr.fedorainfracloud.org/coprs/g/{}/package/{}/rebuild".format(project['full_name'][1:], p['name'])
config_file = './config.ini'
if len(sys.argv) == 2:
config_file = sys.argv[1]
config = load_config(file=config_file)
client_next = create_copr_client(copr_url = config.get('next', 'url', fallback = None),
configfile = config.get('next', 'config', fallback = None))
client_current = create_copr_client(copr_url = config.get('current', 'url', fallback = None),
configfile = config.get('current', 'config', fallback = None))
missing = []
failed = []
project_current = client_current.project_proxy.get(config['current']['owner'], config['current']['project'])
project_next = client_current.project_proxy.get(config['next']['owner'], config['next']['project'])
response = client_next.monitor_proxy.monitor(config['next']['owner'], config['next']['project'])
packages_next = response['packages']
response = client_current.monitor_proxy.monitor(config['current']['owner'], config['current']['project'])
packages_current = response['packages']
add_url_build_log_field(project_current, packages_current)
add_url_build_log_field(project_next, packages_next)
add_url_rebuild_field(project_current, packages_current)
add_url_rebuild_field(project_next, packages_next)
#print(json.dumps(packages_next))
results = {}
next_chroot = list(project_next['chroot_repos'].keys())[0]
next_os_version = "-".join(next_chroot.split('-')[0:2])
try:
filename = f'status/{next_os_version}.cfg'
notes_file = open(filename)
notes_cfg = configparser.ConfigParser()
notes_cfg.optionxform = str
notes_cfg.read_file(notes_file)
except Exception as e:
try:
notes_file=open('status/' + os.path.basename(config_file)[:-4] + ".cfg")
notes_cfg = configparser.ConfigParser()
notes_cfg.optionxform = str
notes_cfg.read_file(notes_file)
except Exception as e:
print(e, f"Failed to load notes file: {filename}")
notes_cfg = {'willfix' : {}, 'wontfix' : {}}
for p in packages_next:
state = get_combined_build_state(p['chroots'])
if state == 'succeeded':
continue
if p['name'] in notes_cfg['wontfix']:
continue
failed.append(p)
for p_next in failed:
p_current = get_package(p_next['name'], packages_current)
if not p_current:
p_current = {'name' : p_next['name'], 'chroots' : {} }
for c in project_current['chroot_repos']:
if c in p_current['chroots']:
continue
p_current['chroots'][c] = { 'state' : 'missing', 'url_build_log' : '' }
result = {}
result['name'] = p_next['name']
result['os_version'] = next_os_version
result['builds_a'] = p_current
result['builds_b'] = p_next
result['note'] = ''
if p_next['name'] in notes_cfg['willfix']:
result['note'] = notes_cfg['willfix'][p_next['name']]
results[p_next['name']] = result
with open("packages.json", "w") as out:
json.dump(results, out, indent=2)