File: pkgproblemresolver.py

package info (click to toggle)
python-apt 0.7.100.1%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 2,748 kB
  • ctags: 1,919
  • sloc: cpp: 8,937; python: 5,750; makefile: 89; sh: 9
file content (70 lines) | stat: -rw-r--r-- 2,268 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env python2.4
#
# Test for the DepCache code
#

import apt_pkg
import sys


def main():
    apt_pkg.init()
    cache = apt_pkg.Cache()
    depcache = apt_pkg.DepCache(cache)
    depcache.Init()
    i=0
    all=cache.PackageCount
    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.GetCandidateVer(pkg)
        if ver is not None:
            depcache.MarkInstall(pkg)
            if depcache.BrokenCount > 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.MarkedInstall(pkg):
                        print "broken in archive: %s " % pkg.Name
                fixer = None
            if depcache.InstCount == 0:
                if depcache.IsUpgradable(pkg):
                    print "Error marking %s for install" % x
            for p in cache.Packages:
                if depcache.MarkedInstall(p) or depcache.MarkedUpgrade(p):
                    depcache.MarkKeep(p)
            if depcache.InstCount != 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.InstCount
    print "To remove: %s " % depcache.DelCount
    print "Kept back: %s " % depcache.KeepCount

    print "Trying DistUpgrade:"
    depcache.Upgrade(True)
    print "To install: %s " % depcache.InstCount
    print "To remove: %s " % depcache.DelCount
    print "Kept back: %s " % depcache.KeepCount


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