blob: 59e050ba794e509f92fc444c7307f4dee015e2fe (
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
#!/usr/bin/python3
#
# LOW LEVEL example how to deal with the depcache
#
# you probably do not want to use this low level code and use
# the high level "apt" interface instead that can do all this
# but with a nicer API
import apt_pkg
from progress import TextFetchProgress
from apt.progress.text import OpProgress
# init
apt_pkg.init()
progress = OpProgress()
cache = apt_pkg.Cache(progress)
print("Available packages: %s " % cache.package_count)
print("Fetching")
progress = TextFetchProgress()
source = apt_pkg.SourceList()
cache.update(progress, source)
iter = cache["base-config"]
print("example package iter: %s" % iter)
# get depcache
print("\n\n depcache")
depcache = apt_pkg.DepCache(cache)
depcache.read_pinfile()
print("got a depcache: %s " % depcache)
print("Marked for install: %s " % depcache.inst_count)
print("\n\n Reinit")
depcache.init(progress)
# sys.exit()
# get a canidate version
ver = depcache.get_candidate_ver(iter)
print("Candidate version: %s " % ver)
print("\n\nQuerry interface")
print(f"{iter.name}.is_upgradable(): {depcache.is_upgradable(iter)}")
print("\nMarking interface")
print("Marking '%s' for install" % iter.name)
depcache.mark_install(iter)
print("Install count: %s " % depcache.inst_count)
print(f"{iter.name}.marked_install(): {depcache.marked_install(iter)}")
print(f"{iter.name}.marked_upgrade(): {depcache.marked_upgrade(iter)}")
print(f"{iter.name}.marked_delete(): {depcache.marked_delete(iter)}")
print("Marking %s for delete" % iter.name)
depcache.mark_delete(iter)
print("del_count: %s " % depcache.del_count)
print(f"{iter.name}.marked_delete(): {depcache.marked_delete(iter)}")
iter = cache["apt"]
print("\nMarking '%s' for install" % iter.name)
depcache.mark_install(iter)
print("Install count: %s " % depcache.inst_count)
print(f"{iter.name}.marked_install(): {depcache.marked_install(iter)}")
print(f"{iter.name}.marked_upgrade(): {depcache.marked_upgrade(iter)}")
print(f"{iter.name}.marked_delete(): {depcache.marked_delete(iter)}")
print("Marking %s for keep" % iter.name)
depcache.mark_keep(iter)
print("Install: %s " % depcache.inst_count)
iter = cache["python-apt"]
print("\nMarking '%s' for install" % iter.name)
depcache.mark_install(iter)
print("Install: %s " % depcache.inst_count)
print("Broken count: %s" % depcache.broken_count)
print("fix_broken() ")
depcache.fix_broken()
print("Broken count: %s" % depcache.broken_count)
print("\nPerforming upgrade")
depcache.upgrade()
print("Keep: %s " % depcache.keep_count)
print("Install: %s " % depcache.inst_count)
print("Delete: %s " % depcache.del_count)
print("usr_size: %s " % apt_pkg.size_to_str(depcache.usr_size))
print("deb_size: %s " % apt_pkg.size_to_str(depcache.deb_size))
for pkg in cache.packages:
if (
pkg.current_ver is not None
and not depcache.marked_install(pkg)
and depcache.is_upgradable(pkg)
):
print("upgrade didn't upgrade (kept): %s" % pkg.name)
print("\nPerforming Distupgrade")
depcache.upgrade(True)
print("Keep: %s " % depcache.keep_count)
print("Install: %s " % depcache.inst_count)
print("Delete: %s " % depcache.del_count)
print("usr_size: %s " % apt_pkg.size_to_str(depcache.usr_size))
print("deb_size: %s " % apt_pkg.size_to_str(depcache.deb_size))
# overview about what would happen
for pkg in cache.packages:
if depcache.marked_install(pkg):
if pkg.current_ver is not None:
print("Marked upgrade: %s " % pkg.name)
else:
print("Marked install: %s" % pkg.name)
elif depcache.marked_delete(pkg):
print("Marked delete: %s" % pkg.name)
elif depcache.marked_keep(pkg):
print("Marked keep: %s" % pkg.name)
|