summaryrefslogtreecommitdiff
path: root/check-code.liw.fi-versions
blob: 0ea31693f7a1b9e8f27d5bbc1a601002faad2506 (plain)
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
#!/usr/bin/python
#
# All is OK if:
#
#   - every package is in each architecture
#   - every package is in each codename
#   - if the version in unstable is x.y-z, then the version in codename foo
#     is x.y-z.foo


import subprocess
import sys


def produce_package_data():
    with open('/home/liw/code.liw.fi/debian/conf/distributions') as f:
        text = f.read()

    codenames = set(
        line.split()[1]
        for line in text.splitlines() 
        if line.startswith('Codename:'))

    codenames = set(x for x in codenames if x != 'squeeze')

    data = ''
    for codename in codenames:
        p = subprocess.Popen(
            ['reprepro', '-b', '/home/liw/code.liw.fi/debian', 'list', codename],
            stdout=subprocess.PIPE)
        out, err = p.communicate('')
        if p.returncode != 0:
            raise Exception('reprepro failed:\n%s'  % err)
        data += out

    return data


def parse_package_data(text):
    data = []
    for line in text.splitlines():
        s, pkg, version = line.split()
        codename, main, arch = s.split('|')
        if arch.endswith(':'):
            arch = arch[:-1]
        data.append((pkg, codename, arch, version))
    return data


def packages(data):
    return set(p for p, c, a, v in data)


def check_package(data, package):
    # Is the package in every architecture?
    all_arches = set(a for p, c, a, v in data)
    arches_with_p = set(a for p, c, a, v in data if p == package)
    missing_from_arches = all_arches.difference(arches_with_p)
    for arch in missing_from_arches:
        print 'ERROR: package %s not in arch %s' % (package, arch)

    # Is the package in every codename?
    all_codenames = set(c for p, c, a, v in data)
    codenames_with_p = set(c for p, c, a, v in data if p == package)
    missing_from_codenames = all_codenames.difference(codenames_with_p)
    for codename in missing_from_codenames:
        print 'ERROR: package %s not in codename %s' % (package, codename)

    # Does the package have the same version (modulo ".$codename" suffix)
    # in every codename?
    unstable_versions = set(
        v for p, c, a, v in data if p == package and c == 'unstable')
    if len(unstable_versions) == 0:
        print 'ERROR: package %s not in unstable' % package
    elif len(unstable_versions) > 1:
        print 'ERROR: package %s has more than one version in unstable' % \
            package
    else:
        uv = unstable_versions.pop()
        for p, c, a, v in data:
            if p == package and c != 'unstable':
                expected = '%s.%s' % (uv, c)
                if v != expected:
                    print 'ERROR: package %s has version %s, expected %s' % \
                        (package, v, expected)

def main():
    text = produce_package_data()
    data = parse_package_data(text)
    
    for p in sorted(list(packages(data))):
        check_package(data, p)


main()