File: fix-cross-problems.py

package info (click to toggle)
botch 0.24-6.1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,084,624 kB
  • sloc: xml: 11,924,892; ml: 4,489; python: 3,890; sh: 1,268; makefile: 334
file content (97 lines) | stat: -rwxr-xr-x 3,285 bytes parent folder | download | duplicates (4)
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
#!/usr/bin/env python3

import sys

sys.path.append("/usr/share/botch")
from util import read_write_tag_file, parse_dose_yaml, read_yaml_file
from collections import defaultdict


def fix_cross_problems(data, buildpkgs, hostpkgs, verbose=False):
    data = parse_dose_yaml(data)

    if not data.get("bin"):
        return True

    buildpkgdict = defaultdict(list)
    for pkg in buildpkgs:
        buildpkgdict[pkg["Package"]].append(pkg)

    hostpkgdict = defaultdict(list)
    for pkg in hostpkgs:
        hostpkgdict[pkg["Package"]].append(pkg)

    for pkg, types in list(data["bin"].items()):
        for t in types:
            if t == "missing":
                # mark binary package m-a:foreign
                if buildpkgdict.get(pkg):
                    newsections = []
                    for section in buildpkgdict[pkg]:
                        section["Multi-Arch"] = "foreign"
                        newsections.append(section)
                    buildpkgdict[pkg] = newsections
                if hostpkgdict.get(pkg):
                    newsections = []
                    for section in hostpkgdict[pkg]:
                        section["Multi-Arch"] = "foreign"
                        newsections.append(section)
                    hostpkgdict[pkg] = newsections
            elif t == "conflict":
                # mark binary package as m-a:same
                if buildpkgdict.get(pkg):
                    newsections = []
                    for section in buildpkgdict[pkg]:
                        section["Multi-Arch"] = "same"
                        newsections.append(section)
                    buildpkgdict[pkg] = newsections
                if hostpkgdict.get(pkg):
                    newsections = []
                    for section in hostpkgdict[pkg]:
                        section["Multi-Arch"] = "same"
                        newsections.append(section)
                    hostpkgdict[pkg] = newsections
            else:
                return False

    with buildpkgs as f:
        for k in sorted(list(buildpkgdict.keys())):
            for section in buildpkgdict[k]:
                section.dump(f)
                f.write(b"\n")

    with hostpkgs as f:
        for k in sorted(list(hostpkgdict.keys())):
            for section in buildpkgdict[k]:
                section.dump(f)
                f.write(b"\n")
    return True


if __name__ == "__main__":
    import argparse

    parser = argparse.ArgumentParser(
        description=(
            "fix build and host architecture Packages files "
            + "according to the result of botch-dose2html"
        )
    )
    parser.add_argument(
        "data",
        metavar="dose.yaml",
        type=read_yaml_file,
        help="input yaml result as produced by " + "dose-builddebcheck",
    )
    parser.add_argument(
        "buildpackages", type=read_write_tag_file, help="build architecture Packages"
    )
    parser.add_argument(
        "hostpackages", type=read_write_tag_file, help="host architecture Packages"
    )
    parser.add_argument("-v", "--verbose", action="store_true", help="be verbose")
    args = parser.parse_args()
    ret = fix_cross_problems(
        args.data, args.buildpackages, args.hostpackages, args.verbose
    )
    exit(not ret)