-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathrun.py
177 lines (159 loc) · 4.35 KB
/
run.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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
import logging
import click
from status_checker import StatusChecker
from datetime import date as dt
from datetime import datetime
try:
import config as cfg
except ImportError:
class cfg(object):
slots_to_check = StatusChecker.slots_to_check
platforms_to_check = StatusChecker.platforms_to_check
projects_to_check = StatusChecker.projects_to_check
@click.group()
@click.option("--verbosity", default="INFO", help="verbosity of the logger")
def cli(verbosity):
root = logging.getLogger()
root.setLevel(verbosity)
def common(func):
func = click.option(
"--date",
default=dt.today().strftime(StatusChecker.date_format),
help=f"date of the slot to check (in '{StatusChecker.date_format}')",
)(func)
func = click.option(
"--slots",
default=cfg.slots_to_check,
help="list of nightly slot names to check",
multiple=True,
)(func)
func = click.option(
"--platforms",
default=cfg.platforms_to_check,
help="list of platform names to check",
multiple=True,
)(func)
func = click.option(
"--projects",
default=cfg.projects_to_check,
help="list of project names to check",
multiple=True,
)(func)
return func
@click.command()
@common
def current_status(date, slots, platforms, projects):
"""Print in the terminal the summary of nightly slots"""
checker = StatusChecker(
slot_names=slots,
platform_names=platforms,
project_names=projects,
)
checker.check_status(
date_to_check=datetime.strptime(
date,
StatusChecker.date_format,
),
)
@click.command()
@common
@click.option(
"--days",
default=7,
help="number of days to include in the report",
)
@click.option(
"--html",
default=True,
help="write in HTML format",
)
@click.option(
"--filepath",
default="output.html",
help="path to a file",
)
def dqcs_report(
date,
slots,
platforms,
projects,
days,
html,
filepath,
):
"""Prepare the DQCS report."""
checker = StatusChecker(
slot_names=slots,
platform_names=platforms,
project_names=projects,
)
checker.check_status(
date_to_check=datetime.strptime(
date,
StatusChecker.date_format,
),
days=days,
html=html,
filepath=filepath,
)
@click.command()
@common
def mkconfig(date, slots, platforms, projects):
"""Generate config.py to customize
selection of slots, platforms and projects."""
cfg_code = """
# Module to customize default configuration of nightly-status-checker
slots_to_check = [
{slots_list}
]
projects_to_check = [
{project_list}
]
platforms_to_check = [
{platform_list}
]
"""
pretty_sep = ",\n "
project_list = []
platform_list = []
checker = StatusChecker(
slot_names=slots,
platform_names=platforms,
project_names=projects,
)
slots_list = [sn for sn in checker._slots.keys()]
miss_slots = [
sn for sn in StatusChecker.slots_to_check if sn not in slots_list
]
if len(miss_slots) > 0:
logging.warning(
"Hardcoded default slots {} not found in Nightly page."
" Maybe update package!".format(", ".join(miss_slots))
)
for slot, build in checker._slots.items():
r = checker._get_Platforms_Projects_for_slot(slot, build)
project_list += [pn for pn in r[1] if pn not in project_list]
platform_list += [pn for pn in r[0] if pn not in platform_list]
slots_str = pretty_sep.join(['"{}"'.format(ss) for ss in slots_list])
projects_str = pretty_sep.join(['"{}"'.format(ss) for ss in project_list])
platforms_str = pretty_sep.join(
['"{}"'.format(ss) for ss in platform_list]
)
with open("config.py", "w", encoding="utf-8") as fp:
fp.write(
cfg_code.format(
slots_list=slots_str,
project_list=projects_str,
platform_list=platforms_str,
)
)
fp.flush()
logging.info(
"'config.py' file written to disk. "
"Edit accordingly and run script again for desired function."
)
cli.add_command(current_status)
cli.add_command(dqcs_report)
cli.add_command(mkconfig)
if __name__ == "__main__":
cli()