summaryrefslogtreecommitdiffstats
path: root/debian/lib/python/debian_linux/abi.py
blob: 8532db16da8e42f55b66a0eb7feb2b1897e2e12e (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
class Symbol(object):
    def __init__(self, name, module, version, export):
        self.name, self.module = name, module
        self.version, self.export = version, export

    def __eq__(self, other):
        if not isinstance(other, Symbol):
            return NotImplemented

        # Symbols are resolved to modules by depmod at installation/
        # upgrade time, not compile time, so moving a symbol between
        # modules is not an ABI change.  Compare everything else.
        if self.name != other.name:
            return False
        if self.version != other.version:
            return False
        if self.export != other.export:
            return False

        return True

    def __ne__(self, other):
        ret = self.__eq__(other)
        if ret is NotImplemented:
            return ret
        return not ret


class Symbols(dict):
    def __init__(self, file=None):
        if file:
            self.read(file)

    def read(self, file):
        for line in file:
            version, name, module, export = line.strip().split()
            self[name] = Symbol(name, module, version, export)

    def write(self, file):
        for s in sorted(self.values(), key=lambda i: i.name):
            file.write("%s %s %s %s\n" %
                       (s.version, s.name, s.module, s.export))