generate_html.py 30.1 KB
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 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713
#!/usr/bin/env python3
#
# Copyright (C) 2013 Johannes Schauer <j.schauer at email.de>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# published by the Free Software Foundation, either version 3 of the
# License, or (at your option) any later version.

import sys
import json
from datetime import datetime

if len(sys.argv) != 4:
    print("usage: %s date mainarchs portarchs")
    exit(1)

newestdate = datetime.strptime(sys.argv[1], "%Y%m%dT%H%M%SZ")
mainarchs=sorted(sys.argv[2].split())
portarchs=sorted(sys.argv[3].split())

archs=sorted(mainarchs+portarchs)

data = dict()

for arch in archs:
    try:
        data[arch] = json.load(open("bootstrap.debian.net/%s/stats.json"%arch))
    except IOError:
        data[arch] = None


from collections import defaultdict

footer = """

<hr />

<p>The JSON data used to generate these pages was computed using botch, the
bootstrap/build ordering tool chain. The source code of botch can be
redistributed under the terms of the LGPL3+ with an OCaml linking exception.
The source code can be retrieved from <a
href="https://gitlab.mister-muffin.de/debian-bootstrap/botch">
https://gitlab.mister-muffin.de/debian-bootstrap/botch</a></p>

<p>The html pages were generated by code which can be retrieved from <a
href="https://gitlab.mister-muffin.de/debian-bootstrap/bootstrap_debian_net">
https://gitlab.mister-muffin.de/debian-bootstrap/bootstrap_debian_net</a> and which can
be redistributed under the terms of the AGPL3+</p>

<p>For questions and bugreports please contact j [dot] schauer [at] email [dot]
de.</p>
"""

# now, generate individual pages for all relevant source packages

from operator import itemgetter
from functools import cmp_to_key
import apt_pkg
apt_pkg.init()

sources = defaultdict(lambda: defaultdict(lambda: defaultdict(lambda: {arch:False for arch in archs if data[arch]})))

def cmp(a,b):
    return (a > b) - (a < b)

# sort first by binary/source, then by name, then by version
def binpkgcmp(a, b):
    n1, a1, v1 = a
    n2, a2, v2 = b
    name_cmp = cmp(n1, n2)
    if name_cmp:
        return name_cmp
    ver_cmp = apt_pkg.version_compare(v1, v2)
    if ver_cmp:
        return ver_cmp
    arch_cmp = cmp(a1,a2)
    if arch_cmp:
        return arch_cmp
    raise Exception("duplicate binary package")

def srcpkgcmp(a, b):
    n1, v1 = a
    n2, v2 = b
    name_cmp = cmp(n1, n2)
    if name_cmp:
        return name_cmp
    ver_cmp = apt_pkg.version_compare(v1, v2)
    if ver_cmp:
        return ver_cmp
    raise Exception("duplicate source package")

# sort first by binary/source/scc, then by name, then by version
def vertcmp(a, b):
    t1, data1 = a
    t2, data2 = b
    if t1 == 'SCC' or t2 == 'SCC':
        raise Exception("SCC not implemented yet")
    elif t1 == 'SrcPkg' and t2 == 'InstSet':
        return -1
    elif t1 == 'InstSet' and t2 == 'SrcPkg':
        return 1
    elif t1 == 'InstSet' and t2 == 'InstSet':
        bin1,is1 = data1
        bin2,is2 = data2
        pkg_cmp = binpkgcmp(bin1,bin2)
        if bin_cmp:
            return bin_cmp
        is_cmp = cmp(len(is1),len(is2))
        if is_cmp:
            return is_cmp
        for p1,p2 in zip(is1,is2):
            p_cmp = binpkgcmp(p1,p2)
            if p_cmp:
                return p_cmp
        raise Exception("duplicate InstSet vertex")
    elif t1 == 'SrcPkg' and t2 == 'SrcPkg':
        try:
            return srcpkgcmp(data1,data2)
        except:
            print(("FIXME: duplicate SrcPkg vertex %s"%data1[0]))
            return 0
    else:
        raise Exception("invalid vertex type: %s"%t2)

# strip the architecture to merge lists from different archs
def binpkg_normalize_arch(e,buildarch,hostarch):
    n,a,v = e
    if a == 'all':
        return (n,a,v)
    elif a == hostarch:
        return (n,"host",v)
    elif a == buildarch:
        return (n,"build",v)
    else:
        raise Exception("architecture %s is neither build nor host arch"%a)

def vertex_normalize_arch(v,buildarch,hostarch):
    t,data = v
    if t == 'SrcPkg':
        n,v = data
        return ('SrcPkg', (n,v))
    elif t == 'InstSet':
        pkg,instset = data
        return ("InstSet", (binpkg_normalize_arch(pkg,buildarch,hostarch), sort_binpkglist(instset,buildarch,hostarch)))
    elif t == 'SCC':
        raise Exception("SCC not implemented yet")
    else:
        raise Exception("invalid vertex type: %s"%t2)

# rotate elements of cycle so that the smallest comes first
# strip the architecture to merge lists from different archs
def normalize_cycle(cycle,buildarch,hostarch):
    def pkgtcmp(a, b):
        return vertcmp(a[1], b[1])
    cycle = [vertex_normalize_arch(v,buildarch,hostarch) for v in cycle]
    smallest_idx = min(enumerate(cycle), key=cmp_to_key(pkgtcmp))[0]
    rotated = cycle[smallest_idx:]+cycle[:smallest_idx]
    return tuple(rotated)

def normalize_edge(edge,buildarch,hostarch):
    return tuple([vertex_normalize_arch(edge[0],buildarch,hostarch), vertex_normalize_arch(edge[1],buildarch,hostarch)])

# sort elements of a list so that the smallest comes first
def sort_binpkglist(l,buildarch,hostarch):
    return tuple(sorted([binpkg_normalize_arch(e,buildarch,hostarch) for e in l], key=cmp_to_key(binpkgcmp)))
def sort_srcpkglist(l):
    return tuple(sorted([(n,v) for n,v in l], key=cmp_to_key(srcpkgcmp)))

# calculate source and binary ratio cutoff values
source_ratios = list()
binary_ratios = list()

for arch in archs:
    if not data[arch]:
        continue
    for scc in data[arch]['buildgraph']['sccs']:
        for _, b, _, o in scc['ratio_source']:
            source_ratios.append(float(b)/len(o))
        for _, s, o in scc['ratio_binary']:
            binary_ratios.append(float(s)/len(o))

source_ratios.sort(reverse=True)
binary_ratios.sort(reverse=True)
if not source_ratios:
    source_ratio_cutoff = 0
else:
    source_ratio_cutoff = source_ratios[len(source_ratios)//10]
if not binary_ratios:
    binary_ratio_cutoff = 0
else:
    binary_ratio_cutoff = binary_ratios[len(binary_ratios)//10]

sources_in_scc = {arch:defaultdict(set) for arch in archs if data[arch]}

for arch in archs:
    # so far, this only displays results from native bootstrapping
    buildarch = hostarch = arch
    if not data[arch]:
        continue
    for name in ['type1cycles', 'type2cycles']:
        for src, l1, l2 in data[arch]['srcgraph'][name]:
            idx = (sort_binpkglist(l1,buildarch,hostarch), sort_binpkglist(l2,buildarch,hostarch))
            sources[tuple(src)][name][idx][arch] = True
            sources_in_scc[arch][src[0]].add(src[1])
    for src, l in data[arch]['srcgraph']['type3cycles']:
        idx = (sort_binpkglist(l,buildarch,hostarch),)
        sources[tuple(src)]['type3cycles'][idx][arch] = True
        sources_in_scc[arch][src[0]].add(src[1])
    for scc in data[arch]['buildgraph']['sccs']:
        for c in scc['cycles']:
            idx = (normalize_cycle(c,buildarch,hostarch),)
            for p in idx[0]:
                if p[0] == 'SrcPkg':
                    sources[p[1]]['cycles'][idx][arch] = True
                    sources_in_scc[arch][p[1][0]].add(p[1][1])
        for name in ['cycleedge', 'sb']:
            for edge, a in scc[name]:
                idx = (normalize_edge(edge,buildarch,hostarch),a)
                k = idx[0][0]
                if k[0] == 'SrcPkg':
                    sources[k[1]][name][idx][arch] = True
                    sources_in_scc[arch][k[1][0]].add(k[1][1])
        for name in ['weak', 'builddeps']:
            for src, l in scc[name]:
                idx = (sort_binpkglist(l,buildarch,hostarch),)
                sources[tuple(src)][name][idx][arch] = True
                sources_in_scc[arch][src[0]].add(src[1])
        for src, b, n, o in scc['ratio_source']:
            idx = (tuple(src),b,sort_binpkglist(n,buildarch,hostarch),sort_srcpkglist(o))
            if float(b)/len(o) < source_ratio_cutoff:
                continue
            for s in o:
                sources[tuple(s)]['ratio_source'][idx][arch] = True
                sources_in_scc[arch][s[0]].add(s[1])
        for b, s, o in scc['ratio_binary']:
            idx = (binpkg_normalize_arch(b,buildarch,hostarch),s,sort_srcpkglist(o))
            if float(s)/len(o) < binary_ratio_cutoff:
                continue
            for src in o:
                sources[tuple(src)]['ratio_binary'][idx][arch] = True
                sources_in_scc[arch][src[0]].add(src[1])
        for src, l in scc['fas']:
            idx = (sort_binpkglist(l,buildarch,hostarch),)
            sources[tuple(src)]['fas'][idx][arch] = True
            sources_in_scc[arch][src[0]].add(src[1])
        for vert, a in scc['sap']:
            if vert[0] == 'SrcPkg':
                k = vertex_normalize_arch(vert,buildarch,hostarch)[1]
                sources[k]['sap'][(a,)][arch] = True
                sources_in_scc[arch][k[0]].add(k[1])

sources_in_scc_d = defaultdict(set)
for arch in archs:
    if not data[arch]:
        continue
    for k,v in list(sources_in_scc[arch].items()):
        sources_in_scc_d[k].update(v)

# string of package
def sob(binpkg):
    name, arch, ver = binpkg
    fullname = "%s:%s&nbsp;(=&nbsp;%s)"%(name,arch, ver)
    return "<span class=\"pkg\" title=\"%s\">%s</span>"%(fullname, name)
def sos(srcpkg):
    name, ver = srcpkg
    fullname = "src:%s&nbsp;(=&nbsp;%s)"%(name,ver)
    return "<a href=\"/source/%s_%s.html\" class=\"pkg\" title=\"%s\">src:%s</a>"%(name, ver, fullname, name)

# string of list
def sobl(l):
    return ", ".join([sob(pkg) for pkg in l])
def sosl(l):
    return ", ".join([sos(pkg) for pkg in l])

# string of vector
def sov(v):
    t, data = v
    if t == 'SrcPkg':
        name, ver = data
        fullname = "src:%s&nbsp;(=&nbsp;%s)"%(name,ver)
        return "<a href=\"/source/%s_%s.html\" class=\"pkg\" title=\"%s\">%s</a>"%(name, ver, fullname, "src:"+name)
    elif t == 'InstSet':
        (name, arch, ver),instset = data
        instset = ", ".join(["%s:%s&nbsp;(=&nbsp;%s)" % (n, a, v)
                            for n, a, v in instset])
        fullname = "%s:%s&nbsp;(=&nbsp;%s), installation set = { %s }"%(name,arch,ver,instset)
        return "<span class=\"pkg\" title=\"%s\">%s</span>"%(fullname, name)
    elif t == 'SCC':
        raise Exception("SCC not implemented yet")
    else:
        raise Exception("invalid vertex type: %s"%t)

# string of cycle
def soc(c):
    res = sov(c[0])
    for v in c[1:]:
        t,data = v
        if t == 'SrcPkg':
            # the previous edge was a "buildsfrom" edge
            res += " <span title=\"builds from\" class=\"arrowouter\"><span class=\"arrowinner\">→</span></span> "
        elif t == 'InstSet':
            # the previous edge was a "builddepends" edge
            res += " <span title=\"build depends\" class=\"arrowouter\"><span class=\"arrowinner\">⇢</span></span> "
        else:
            raise Exception("invalid vertex type: %s"%t)
        res += sov(v)
    return res

tables = {
        'type1cycles': {
            'title': 'Type 1 Cycles',
            'descr': """<p>A source package directly Build-Depends on a binary package it itself builds.</p>
                        <p>The build dependency indicated in the second column <b>must</b> be removable.</p>""",
            'heads': ["strongly depends on", "because it build-depends on"],
            'printer': lambda l1,l2: (sobl(l1),sobl(l2)),
            'order': 0
            },
        'type2cycles': {
            'title': 'Type 2 Cycles',
            'descr': """<p>A source package indirectly strongly Build-Depends on a binary package it builds through one of its direct build dependencies.</p>
                     <p>The build dependency indicated in the second column <b>must</b> be removable.</p>""",
            'heads': ["strongly depends on", "because it build-depends on"],
            'printer': lambda l1,l2: (sobl(l1),sobl(l2)),
            'order': 0
            },
        'type3cycles': {
            'title': 'Type 3 Cycles',
            'descr': """<p>Not-strong self-cycles which can probably be solved by choosing a different installationset</p>""",
            'heads': ["in non-strong cycle with"],
            'printer': lambda l: (sobl(l),),
            'order': 0
            },
        'cycles': {
            'title': 'Cycles',
            'descr': """<p>Small dependency cycles. The second column shows the binary and source packages involved in the cycle.</p>""",
            'heads': ["Length", "Cycle"],
            'printer': lambda l: (str(len(l)),soc(l)),
            'order': 0
            },
        'cycleedge': {
            'title': 'Amount of Cycles through Edges',
            'descr': """<p>After enumerating all cycles in the graph up to a certain maximum length, the first column indicates the amount of cycles that the edge in the second column is part of. Removing an edge with many cycles through it, immediately breaks all those cycles.</p>""",
            'heads': ["Amount","Edge"],
            'printer': lambda c,a: (str(a),soc(c)),
            'order': 1
            },
        'builddeps': {
            'title': 'Amount of Missing Build Dependencies',
            'descr': """<p>This is the amount of build dependencies that cannot be satisfied. If the amount is low, then it might be worthwhile making those build dependencies droppable.</p>""",
            'heads': ["Amount", "Build Dependencies"],
            'printer': lambda l: (str(len(l)),sobl(l)),
            'order': 0
            },
        'ratio_source': {
            'title': "Ratio Source Heuristic",
            'descr': """<p>If the source packages in the fifth column (which this package is part of) can be built without the binary packages in the fourth column, the the source package in the second column does not have to be built anymore and therefore, does not draw in the amount of binary packages indicated in the third column. The ratio between the amount of source packages in the fifth column and the number in the third column is given in the first column.</p><p>Consider making the binary packages indicated in the fourth column droppable.</p>""",
            'heads': ["Ratio","Source Package", "Missing Build Dependencies", "Source Package is needed by", "Those Packages are Build Dependencies of"],
            'printer': lambda s,b,n,o: (str(float(b)/len(o)),sos(s),str(b),sobl(n),sosl(o)),
            'order': 1
            },
        'ratio_binary': {
            'title': "Ratio Binary Heuristic",
            'descr': """<p>If the source packages in the fourth column can be built without the binary packages in the second column, then the amount of source packages indicated in the third column will not be needed anymore. The ratio between the amount of source packages in the fourth column and the number in the third column is given in the first column</p><p>Consider making the binary packages indicated in the second column droppable.</p>""",
            'heads': ["Ratio", "Binary Package", "Needs Source Package", "Is Build Dependency of"],
            'printer': lambda b,s,o: (str(float(s)/len(o)),sob(b),str(s),sosl(o)),
            'order': 1
            },
        'weak': {
            'title': "Only Weak Build Dependencies Missing",
            'descr': """<p>This source packages only lacks the following \"weak\" build dependencies as classified as such by <a href=\"https://gitlab.mister-muffin.de/debian-bootstrap/botch/blob/master/droppable/weak-build-dependencies.list\">this list</a>.</p>""",
            'heads': ["Amount", "Weak Build Dependencies"],
            'printer': lambda l: (str(len(l)),sobl(l)),
            'order': 0
            },
         'fas': {
            'title': "Feedback Arc Set",
            'descr': """<p>Some build dependencies of this source package are part of a small <a href="https://en.wikipedia.org/wiki/Feedback_arc_set">feedback arc set</a> which will make the <a href="https://en.wikipedia.org/wiki/Strongly_connected_component">strongly connected component</a> containing this source package <a href="https://en.wikipedia.org/wiki/Directed_acyclic_graph">acyclic</a>.</p><p>Consider making the binary packages indicated in the first column droppable.</p>""",
            'heads': ["Build Dependencies to Drop"],
            'printer': lambda l: (sobl(l),),
            'order': 0
            },
         'sap': {
            'title': "Strong Articulation Points",
            'descr': """<p>This source package is a strong articulation point of the strongly connected component containing this source package. The number of strongly connected components into which the containing strongly connected component would be split into if this source package was buildable/available is indicated in the first column.</p><p>If the number in the first column is high, consider making this source package cross compilable.</p>""",
            'heads': ["Amount of SCC"],
            'printer': lambda a: (str(a),),
            'order': 1
            },
         'sb': {
            'title': "Strong Bridges",
            'descr': """<p>Some build dependencies of this source packages are a strong bridge of the strongly connected component containing this source package. The number of strongly connected components into which the containing strongly connected component would be split into if the respective build dependency was droppable is indicated in the first column.</p><p>If the number in the first column is high, consider making the build dependency in the second column optional.</p>""",
            'heads': ["Amount of SCC", "Edge"],
            'printer': lambda c,a: (str(a),soc(c)),
            'order': 1
            }
        }

controls = """<form>
  <a href="#" class="first">first</a>
  <a href="#" class="prev">prev</a>
  <input type="text" class="pagedisplay"/>
  <a href="#" class="next">next</a>
  <a href="#" class="last">last</a>
  <select class="pagesize">
    <option selected="selected" value="10">10</option>
    <option value="25">25</option>
    <option value="50">50</option>
    <option value="100">100</option>
  </select>
  per page (%d rows in total)
</form>"""

def render_table(name,src,ver):
    f.write('<h2>%s</h2>%s'%(tables[name]['title'],tables[name]['descr']))
    f.write('<div id=\"%s_pager\">%s</div>'%(name,controls%len(sources[src,ver][name])))
    f.write('<table class="tablesorter" id="%s"><thead><tr>'%name)
    for head in tables[name]['heads']:
        f.write('<th>%s</th>'%head)
    for arch in archs:
        if data[arch]:
            f.write('<th>%s</th>'%arch)
    f.write('</tr></thead><tbody>')
    for k,v in list(sources[src,ver][name].items()):
        f.write('<tr><td>'+'</td><td>'.join(tables[name]['printer'](*k))+'</td>')
        for arch in archs:
            if not data[arch]:
                continue
            if v[arch]: f.write('<td>x</td>')
            else:       f.write('<td>&nbsp;</td>')
        f.write('</tr>')
    f.write('</tbody></table>')

for src, ver in sources:
    f=open("bootstrap.debian.net/source/%s_%s.html"%(src,ver), "w", encoding="utf8")
    f.write("""<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Bootstrappability of src:%s in Debian Sid as of %s</title>
<link href="/webresources/style.css" rel="stylesheet" />
<style>
table {font-size: 1em !important}
.pkg:hover {background-color: #e6EEEE}
.arrowouter {
    display: inline-block;
    height: 1em;
    overflow: hidden;
    vertical-align: bottom;
}
.arrowinner {
    display:block;
    font-size: 2em;
    margin-top: -0.4em;
}
</style>
<script type="text/javascript" src="/webresources/jquery.js"></script>
<script type="text/javascript" src="/webresources/jquery.tablesorter.js"></script>
<script type="text/javascript" src="/webresources/jquery.tablesorter.pager.js"></script>
<script>
  $(document).ready(function() {
    $.each($("table.tablesorter"), function(index, val) {
      var id = $(val).attr('id');
      $(val).tablesorter({widthFixed:true}).tablesorterPager({container: $('#' + id + '_pager'), positionFixed: false});"""%(src,newestdate.isoformat()))
    for name,val in list(tables.items()):
        f.write("      $('#%s').trigger(\"sorton\",[[[0,%d]]]);"%(name,val['order']))
    f.write("""    });
});
</script>
</head>
<body>
<h1>%s (%s)</h1>

last updated: %s

<p>Click on the table headers to sort by that column. Shift+Click allows to sort by multiple columns.</p>
<p>Hover over a package name for architecture and version information.</p>
"""%(src,ver,newestdate.isoformat()))
    for name in ['type1cycles', 'type2cycles', 'type3cycles','cycles','cycleedge','builddeps','ratio_source','ratio_binary','weak','srcbinstats','fas','sap','sb']:
        if sources[src,ver].get(name):
            render_table(name,src,ver)
    f.write("""
"""+footer+"""
</body>
</html>""")
    f.close()

for srcname,versions in list(sources_in_scc_d.items()):
    f=open("bootstrap.debian.net/source/%s.html"%srcname, "w", encoding="utf8")
    f.write("""<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Bootstrappability of src:%s in Debian Sid as of %s</title>
<link href="/webresources/style.css" rel="stylesheet" />
</head>
<body>
<h1>src:%s</h1>

last updated: %s

<p>For this source package, information is available for the following
versions:</p>

<table>
  <tr>
    <th>Version</th>
"""%(srcname,newestdate.isoformat(),srcname,newestdate.isoformat()))
    for arch in archs:
        if not data[arch]:
            continue
        f.write("""    <th>%s</th>\n"""%arch)
    f.write("""  </tr>\n""")
    for ver in versions:
        f.write("""  <tr>\n    <td><a href="/source/%s_%s.html">%s</a></td>\n"""%(srcname,ver,ver))
        for arch in archs:
            if not data[arch]:
                continue
            if ver in sources_in_scc[arch][srcname]:
                f.write("""<td>x</td>""")
            else:
                f.write("""<td>&nbsp;</td>""")
        f.write("""  </tr>\n""")
    f.write("""
</table>

An "x" indicates that a problem report is available for that version of the
source package in the respective architecture.

"""+footer+"""
</body>
</html>""")
    f.close()

now = datetime.now().isoformat()

f=open("bootstrap.debian.net/index.html", "w", encoding="utf8")
f.write("""<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8" />
<title>Bootstrappability of Debian Sid as of %s</title>
</head>
<body>

<p>The job regenerating the resources on bootstrap.debian.net is run every
Monday at 02:00 UTC.</p>

<ul>
  <li>Running <a href="https://gitlab.mister-muffin.de/debian-bootstrap/botch/wikis/home">botch</a> for all architectures (this page below)</li>
  <li><a href="cross_cheated.html">Crossbuild order</a></li>
  <li><a href="importance_metric.html">Source package importance</a></li>
  <li><a href="cross.html">Crossbuild dependency satisfaction for base source packages</a></li> <!-- takes 2.5 hours -->
  <li><a href="cross_all.html">Crossbuild dependency satisfaction for all source packages</a> (takes 28 hours)</li>
  <li><a href="foreign_install.html">Installability of foreign arch binaries</a> (takes 17 hours)</li>
  <li><a href="co_ma_same.html">Co-installability of Multi-Arch: same packages</a> (takes 6 hours)</li>
  <li><a href="ma_interpreter.html">Architecture:all packages affected by the multiarch interpreter problem</a></li>
  <li><a href="history.html">History of graph size</a></li>
  <li><a href="history_cross.html">History crossbuild satisfiability</a></li>
  <li><a href="essential.html">Essential and transitive essential</a></li>
</ul>

<p>last updated: %s</p>

<h1>Overview</h1>

<p>Debian Sid is analyzed for all architectures on a daily basis. After an
architecture has been successfully processed, its results are updated.
Processing might not be successful if some of the %d base source packages (see
below for a list) cannot be compiled. In that case the last successful result
is kept and displayed.</p>

<p>Currently, the assumption is that Essential:yes, build-essential and
debhelper and one of their co-installation sets can be cross compiled without
additional requirements.</p>

<p>A history of the results presented here is not available due to hard disk
space constraints. Only the latest successful runs are kept.</p>

<h1>Data per architecture</h1>

<p>The raw data used to produce these pages was generated from
snapshot.debian.org and is available in JSON format. In case an architecture
failed to bootstrap, an error log is available to debug the problem.</p>
"""%(now,now,len(sources_in_scc_d)))

def print_table(f,archs,port=False):
    f.write("""
<table>
  <tr><th>Arch</th><th>Raw JSON</th><th>Generated from</th><th>timestamp</th><th>failure log</th></tr>""")

    for arch in archs:
        if data[arch]:
            ts = data[arch]['timestamp']
            dtts = datetime.strptime(ts, "%Y%m%dT%H%M%SZ")
            f.write("""
  <tr>
    <td><a href="%s/">%s</a></td>
    <td><a href="%s/stats.json">%s/stats.json</a></td>
    <td>
      <a href="http://snapshot.debian.org/archive/debian%s/%s/dists/sid/main/binary-%s/Packages.gz">packages</a>
      <a href="http://snapshot.debian.org/archive/debian%s/%s/dists/sid/main/source/Sources.gz">sources</a>
    </td>
    <td style="background-color:#%s">%s</td>
    <td>%s</td>
  </tr>"""%(arch,arch,arch,arch,"-ports" if port else "",ts,arch,"-ports" if port else "",ts, "80ff80" if dtts.date() == newestdate.date() else "ffff80",dtts.isoformat(),"""<a href="/%s/log.txt">/%s/log.txt</a>"""%(arch,arch) if dtts.date() != newestdate.date() else "&nbsp;"))
        else:
            f.write("""<tr><td>%s</td><td colspan="3" style="background-color:#ff8080">not bootstrappable</td><td><a href="/%s/log.txt">/%s/log.txt</a></td></tr>"""%(arch,arch,arch))
    f.write("""</table>""")

f.write("""<h2>Official Architectures</h2>""")
print_table(f,mainarchs)

f.write("""<h2>Unofficial Debian Ports</h2>

<p>In contrast to the main archive, version numbers of binary and source
packages in ports are usually not matching. To still allow an overview of
bootstrappability, the following heuristic is used to nevertheless allow
matching binary and source packages: if a binary packages does not have a
matching source package, then the version constraint is dropped and the source
package with the highest version number is associated to the binary
package. For some processing steps, binary packages that do not have a
source package at all (independent of the version) are ignored as well.</p>

""")
print_table(f,portarchs,True)

f.write("""
<h3>Legend</h3>
<table>
  <tr><td style="background-color:#80ff80">Current Debian Sid is bootstrappable in theory (with enough build profile information).</td></tr>
  <tr><td style="background-color:#ffff80">Not bootstrappable (see error log). Showing results of last succesful run.</td></tr>
  <tr><td style="background-color:#ff8080">Has never been bootstrappable (see error log).</td></tr>
</table>

<p>The term "bootstrappable" here means: If enough source packages would have
been modified with build profiles so that the dependency graph can be made
acyclic (for example by following the suggestions given in the pages linked to
in above table) then the architecture would be bootstrappable. Since build
profiles cannot yet be added to source packages in the archive, we cannot yet
have a better measure to display here. Once build profiles are allowed in the
archive, above table can be modified such that the term "bootstrappable" means
that enough source packages in the archive have been modified with build
profiles such that the architecture is bootstrappable. But note that even then,
bootstrappability in practice is not necessarily given as all these analyses
are done on the package meta data only and no actual compilation is performed.
Until build profiles are allowed in the archive, "bootstrappability" is more
connected to the fact that all base source packages can be compiled.</p>

<h1>Data per source package</h1>

<p>The generated html is not only available by architecture but also by source
package. It is available for all source packages which are involved in a
strongly connected component.  All of these source packages must be compilable
for an architecture to be bootstrappable.</p>

<p>The data that was used to generate the individual source package pages was
generated from the JSON data per architecture (see above). This refined data is
available in JSON format as well but is only the data from above presented in a
different structure. It is available from <a
href="/source/stats.json">/source/stats.json</a></p>

<p>It is also possible to get only the list of the affected source package
names/versions in JSON format: <a
href="/source/stats_min.json">/source/stats_min.json</a></p>

<p>Below table lists all source packages that are involved in a strongly
connected component and indicates for which architectures they are
relevant.</p>

<table>
""")

for i,srcname in enumerate(sorted(sources_in_scc_d)):
    if i%20 == 0:
        f.write("""  <tr>\n    <th>Source package</th>\n""")
        for arch in archs:
            if data[arch]:
                f.write("""    <th>%s</th>\n"""%arch)
        f.write("""  </tr>\n""")
    f.write("""  <tr>\n    <td><a href="/source/%s.html">src:%s</a></td>\n"""%(srcname,srcname))
    for arch in archs:
        if not data[arch]:
            continue
        if sources_in_scc[arch][srcname]:
            f.write("""    <td>""")
            for v in sorted(sources_in_scc[arch][srcname], key=cmp_to_key(apt_pkg.version_compare)):
                fullname = "src:%s&nbsp;(=&nbsp;%s)"%(srcname,v)
                shortver = v
                if len(shortver) > 10:
                    shortver = shortver[:10]+"…"
                f.write("""<a href="/source/%s_%s.html" class=\"pkg\" title=\"%s\">%s</a>"""%(srcname,v,fullname,shortver))
            f.write("""</td>\n""")
        else:
            f.write("""    <td>&nbsp;</td>\n""")
    f.write("""  </tr>\n""")

f.write("""</table>\n"""+footer+"""
</body>
</html>""")

# json can't handle tuples as dictionary keys
# turn those dictionaries into key/value tuple lists
dumpable_sources = [(k1,{k2:[(k3,v3) for k3,v3 in list(v2.items())] for k2,v2 in list(v1.items())}) for k1,v1 in list(sources.items())]

with open("bootstrap.debian.net/source/stats.json", "w", encoding="utf8") as f:
    json.dump(dumpable_sources, f, sort_keys=True, indent=2)

with open("bootstrap.debian.net/source/stats_min.json", "w", encoding="utf8") as f:
    json.dump(list(sources.keys()), f, sort_keys=True, indent=2)

f.close()