-
Notifications
You must be signed in to change notification settings - Fork 96
/
check_command.py
101 lines (82 loc) · 3.65 KB
/
check_command.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
class CheckCommand(object):
def __init__(self, api):
self.api = api
def _report(self, project, verbose):
"""Print a single report for a project.
:param project: dict object, converted from JSON.
:param verbose: do verbose check or not
"""
report = []
# Check for superseded requests
for r in project.findall('obsolete_requests/*'):
if r.get('state') == 'superseded':
report.extend(f" - Request {r.get('id')} is superseded by {r.get('superseded_by')}")
# Untracked requests
for r in project.findall('untracked_requests/*'):
report.extend(f" - Request {r.get('id')} is no tracked but is open for the project")
# Status of obsolete requests
for r in project.findall('obsolete_requests/*'):
if r.get('state') == 'superseded':
continue
report.append(f" - {r.get('package')}: {r.get('state')}")
if not verbose:
break
# Missing reviews
for r in project.findall('missing_reviews/review'):
report.append(f" - {r.get('package')}: Missing reviews: {self.api.format_review(r)}")
if not verbose:
break
# Building repositories
if project.find('building_repositories/repo') is not None:
report.append(' - At least following repositories are still building:')
for r in project.findall('building_repositories/*'):
report.append(f" {r.get('repository')}/{r.get('arch')}: {r.get('state')}")
if not verbose:
break
# Broken packages
if project.find('broken_packages/package') is not None:
report.append(' - Following packages are broken:')
for r in project.findall('broken_packages/package'):
report.append(f" {r.get('package')} ({r.get('repository')}): {r.get('state')}")
if not verbose:
break
# openQA results
for check in project.findall('missing_checks/*'):
report.append(' - Missing check: ' + check.get('name'))
for check in project.findall('checks/*'):
state = check.find('state').text
if state != 'success':
info = f" - {state} check: {check.get('name')}"
url = check.find('url')
if url is not None:
info += " " + url.text
report.append(info)
break
if project.get('state') == 'acceptable':
report.insert(0, f" ++ Acceptable staging project {project.get('name')}")
elif project.get('state') != 'empty':
report.insert(0, ' -- %s Project %s still needs attention' % (project.get('state').upper(),
project.get('name')))
return report
def _check_project(self, project):
"""
Check state of one specified staging project
:param project: project to check
"""
info = self.api.project_status(project)
if info.get('state') == 'empty':
return []
return self._report(info, False) + ['']
def perform(self, project):
"""
Check one staging project verbosibly or all of them at once
:param project: project to check, None for all
"""
if project:
report = self._check_project(project)
else:
report = []
for project in self.api.get_staging_projects():
report.extend(self._check_project(project))
print('\n'.join(report))
return True