summaryrefslogtreecommitdiffstats
path: root/tests/old/pkgproblemresolver.py
blob: 89190cf4b44f88d171fd9023201f84b225ae0b44 (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
#!/usr/bin/env python2.4
#
# Test for the DepCache code
#

import sys

import apt_pkg


def main():
    apt_pkg.init()
    cache = apt_pkg.Cache()
    depcache = apt_pkg.DepCache(cache)
    depcache.init()
    i = 0
    all = cache.package_count
    print("Running DepCache test on all packages")
    print("(trying to install each and then mark it keep again):")
    # first, get all pkgs
    for pkg in cache.packages:
        i += 1
        x = pkg.name
        # then get each version
        ver = depcache.get_candidate_ver(pkg)
        if ver is not None:
            depcache.mark_install(pkg)
            if depcache.broken_count > 0:
                fixer = apt_pkg.ProblemResolver(depcache)
                fixer.clear(pkg)
                fixer.protect(pkg)
                # we first try to resolve the problem
                # with the package that should be installed
                # protected
                try:
                    fixer.resolve(True)
                except SystemError:
                    # the pkg seems to be broken, the
                    # returns a exception
                    fixer.clear(pkg)
                    fixer.resolve(True)
                    if not depcache.marked_install(pkg):
                        print("broken in archive: %s " % pkg.name)
                fixer = None
            if depcache.inst_count == 0:
                if depcache.is_upgradable(pkg):
                    print("Error marking %s for install" % x)
            for p in cache.packages:
                if depcache.marked_install(p) or depcache.marked_upgrade(p):
                    depcache.mark_keep(p)
            if depcache.inst_count != 0:
                print("Error undoing the selection for %s" % x)
        print("\r%i/%i=%.3f%%    " % (i, all, (float(i) / float(all) * 100)))

    print()
    print("Trying upgrade:")
    depcache.upgrade()
    print("To install: %s " % depcache.inst_count)
    print("To remove: %s " % depcache.del_count)
    print("Kept back: %s " % depcache.keep_count)

    print("Trying DistUpgrade:")
    depcache.upgrade(True)
    print("To install: %s " % depcache.inst_count)
    print("To remove: %s " % depcache.del_count)
    print("Kept back: %s " % depcache.keep_count)


if __name__ == "__main__":
    main()
    sys.exit(0)