~mvo/command-not-found/snap-support

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
#! /usr/bin/env python
#
# (c) 2008 Canonical, GPL
# Authors:
#  Michael Vogt

from __future__ import print_function

import apt
import apt_pkg
import sys

if __name__ == "__main__":

    if len(sys.argv) < 2:
        print("need scan.data argument")
        sys.exit(1)

    scandata = sys.argv[1]
    apt_pkg.config.set("APT::Get::List-Cleanup", "false")
    for arch in ("i386", "amd64"):
        print("Starting verification for '%s'" % arch)
        apt_pkg.config.set("APT::Architecture", arch)
        cache = apt.Cache(rootdir="./apt/")
        cache.update()
        cache.open(apt.progress.base.OpProgress())
        with open(scandata) as scanfile:
            for line in scanfile:
                (march, comp, pkg, bin) = line.split("|")
                if march != arch:
                    continue
                # check if package is in cache
                if not pkg in cache:
                    print("ERROR: '%s' is not in cache" % pkg)
                    continue
                # check if the component is correct
                if not "/" in cache[pkg].section:
                    realcomp = "main"
                else:
                    realcomp = cache[pkg].section.split("/")[0]
                if comp != realcomp:
                    print("ERROR: '%s' is in wrong component (claims '%s' but is in '%s'" % (pkg, comp, realcomp))
        print("done\n")