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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
#!/usr/bin/python3
# SPDX-License-Identifier: GPL-2.0+
import datetime
import lzma
import apt_pkg
apt_pkg.init()
version_compare = apt_pkg.version_compare
import flask
import flask_sqlalchemy
import jinja2
import sqlalchemy
import werkzeug
app = flask.Flask("crossqa")
app.config["SQLALCHEMY_DATABASE_URI"] = 'sqlite:///db'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
db = flask_sqlalchemy.SQLAlchemy(app)
src_template = """<!DOCTYPE html>
<html>
<head>
<title>{{ sourcepackage|e }} - Debian cross build</title>
<style>
tr.dep.bad td:nth-child(1) {
background-color: #faa;
}
tr.dep.tempbad td:nth-child(1) {
background-color: #ffa;
}
tr.dep.good td:nth-child(1) {
background-color: #afa;
}
tr.build.bad td:nth-child(4) {
background-color: #faa;
}
tr.build.tempbad td:nth-child(4) {
background-color: #ffa;
}
tr.build.good td:nth-child(4) {
background-color: #afa;
}
th {
padding-left: 1em;
padding-right: 1em;
}
td {
padding-left: 1px;
padding-right: 1em;
}
td:last-child {
padding-right: 1px;
}
footer {
margin-top: 3em;
border-top: 1px solid;
}
</style>
</head>
<body>
<header>
<h1>
<a href="https://tracker.debian.org/pkg/{{ sourcepackage|e }}">
{{- sourcepackage|e -}}
</a>
</h1>
</header>
<section>
<h3>Cross build dependency satisfiability</h3>
<table>
<thead>
<tr>
<th>state</th>
<th>architectures</th>
</tr>
</thead>
<tbody>
{%- set okarchs = depresult.pop(None, None) -%}
{%- for reason, archs in depresult.items()|sort -%}
<tr class="dep {{ "tempbad" if reason.startswith("skew") else "bad" }}">
<td>{{ reason|e }}</td>
<td>{{ archs|arch_format }}</td>
</tr>
{%- endfor -%}
{%- if okarchs -%}
<tr class="dep good">
<td>ok</td>
<td>{{ okarchs|arch_format }}</td>
</tr>
{%- endif -%}
</tbody>
</table>
<h5>See also</h5>
<ul>
{%- if show_bootstrapdn -%}
<li>
<a href="https://bootstrap.debian.net/cross_all/{{ sourcepackage|e }}.html">bootstrap.debian.net</a>
</li>
{%- endif -%}
<li>
<a href="https://qa.debian.org/dose/debcheck/cross_unstable_main_amd64/">debcheck</a>
</li>
</ul>
</section>
<section>
<h3>Cross builds</h3>
{%- if builds -%}
<table>
<thead>
<tr>
<th>started</th>
<th>version</th>
<th>architecture</th>
<th>result log</th>
</tr>
</thead>
<tbody>
{%- for build in builds|sort(attribute='starttime', reverse=true) -%}
<tr class="build {{ "good" if build.success else "bad" }}">
<td>
{{- build.starttime|sqltimestamp|formatts -}}
</td>
<td>{{ build.version|e }}</td>
<td>{{ build.architecture|e }}</td>
<td>
<a href="{{ url_for("show_log", filename=build.filename[:-3]) }}">
{{- "ok" if build.success else "failed" -}}
</a>
<a href="{{ url_for("show_log", filename=build.filename) }}">xz</a>
</td>
</tr>
{%- endfor -%}
</tbody>
</table>
{%- else -%}
<p>No build performed yet.</p>
{%- endif -%}
<form method="POST" action="{{ url_for("request_schedule")|e }}">
<input type="submit" name="schedule" value="cross build" />
{{ sourcepackage|e }} for
<input type="hidden" name="source" value="{{ sourcepackage|e }}" />
<select name="architecture">
<option value="any">any</option>
{%- for architecture in architectures|sort -%}
<option value="{{ architecture|e }}">{{ architecture|e }}</option>
{%- endfor -%}
</select>
</form>
</section>
<footer>
<h3>Details about this service</h3>
<ul>
<li>Maintainer: Helmut Grohne <helmut@subdivi.de></li>
<li>Source: git://git.subdivi.de/~helmut/crossqa.git</li>
</ul>
</footer>
</body>
</html>
"""
schedule_template = """<!DOCTYPE html>
<html>
<body>
<p>Scheduled a build of {{ request.form["source"]|e }}
{%- if request.form["architecture"] != "any" %}
for {{ request.form["architecture"]|e -}}
{%- endif %}.
<p>
</body>
</html>
"""
@app.template_filter("sqltimestamp")
def sqltimestamp_filter(s):
strptime = datetime.datetime.strptime
try:
return strptime(s, "%Y-%m-%d %H:%M:%S.%f").replace(microsecond=0)
except ValueError:
return strptime(s, "%Y-%m-%d %H:%M:%S")
def formatts(ts):
assert isinstance(ts, datetime.datetime)
dt = datetime.datetime.utcnow() - ts
if dt < datetime.timedelta(seconds=1):
return "now"
if dt < datetime.timedelta(seconds=100):
return "%d s" % dt.seconds
if dt < datetime.timedelta(minutes=100):
return "%d m" % (dt.seconds // 60)
if dt < datetime.timedelta(days=1):
return "%d h" % (dt.seconds // (60 * 60))
return "%d d" % dt.days
@app.template_filter("formatts")
def formatts_filter(ts):
return jinja2.Markup('<time title="%s" datetime="%s">%s</time>' %
(ts, ts, formatts(ts)))
@app.template_filter('arch_format')
@jinja2.contextfilter
def arch_format_filter(context, some_archs):
if context["architectures"] == some_archs:
return "any"
return ", ".join(sorted(some_archs))
def collect_depstate(conn, source):
version = None
depstate = None
query = sqlalchemy.text("""
SELECT version, architecture, satisfiable, reason
FROM depstate WHERE source = :source;""")
for row in conn.execute(query, source=source):
if version is None or version_compare(version, row.version) > 0:
version = row.version
depstate = {}
depstate[row.architecture] = None if row.satisfiable else row.reason
if version is None:
raise werkzeug.exceptions.NotFound()
depresult = {}
for arch, reason in depstate.items():
depresult.setdefault(reason, set()).add(arch)
return version, depresult
@app.route("/src/<source>")
def show_source(source):
context = dict(sourcepackage=source)
with db.engine.connect() as conn:
query = sqlalchemy.text("SELECT architecture FROM depcheck;")
context["architectures"] = set(row[0] for row in conn.execute(query))
context["version"], context["depresult"] = collect_depstate(conn,
source)
query = sqlalchemy.text("""
SELECT version, architecture, success, starttime, filename
FROM builds WHERE source = :source;""")
context["builds"] = list(conn.execute(query, source=source))
context["show_bootstrapdn"] = \
any(reason and not reason.startswith("skew ")
for reason in context["depresult"].keys())
return flask.render_template_string(src_template, **context)
@app.route("/build/<path:filename>")
def show_log(filename):
if filename.endswith(".xz"):
return flask.send_from_directory("logs", filename,
mimetype="application/octet-stream")
filename = flask.safe_join("logs", filename + ".xz")
try:
return flask.send_file(lzma.open(filename, "rb"),
mimetype="text/plain")
except FileNotFoundError:
raise werkzeug.exceptions.NotFound()
@app.route("/schedule", methods=["POST"])
def request_schedule():
source = flask.request.form["source"]
architecture = flask.request.form["architecture"]
with db.engine.connect() as conn:
query = sqlalchemy.text("""
SELECT 1 FROM depstate WHERE source = :source;""")
if not conn.execute(query, source=source).first():
raise werkzeug.exceptions.BadRequest()
if architecture == "any":
architecture = None
else:
query = sqlalchemy.text("""
SELECT 1 FROM depcheck WHERE architecture = :architecture;""")
if not conn.execute(query, architecture=architecture).first():
raise werkzeug.exceptions.BadRequest()
query = sqlalchemy.text("""
INSERT INTO buildrequests (source, architecture, requesttime)
VALUES (:source, :architecture, datetime('now'));""")
conn.execute(query, source=source, architecture=architecture)
return flask.render_template_string(schedule_template)
|