diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 18:07:41 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 18:07:41 +0000 |
commit | 76926159194e180003aa78de97e5f287bf4325a5 (patch) | |
tree | 2cea7245cdc3f66355900c820c145eba90598766 /doc/examples/checkstate.py | |
parent | Initial commit. (diff) | |
download | python-apt-76926159194e180003aa78de97e5f287bf4325a5.tar.xz python-apt-76926159194e180003aa78de97e5f287bf4325a5.zip |
Adding upstream version 2.7.6.upstream/2.7.6
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'doc/examples/checkstate.py')
-rwxr-xr-x | doc/examples/checkstate.py | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/doc/examples/checkstate.py b/doc/examples/checkstate.py new file mode 100755 index 0000000..d4276e8 --- /dev/null +++ b/doc/examples/checkstate.py @@ -0,0 +1,37 @@ +#!/usr/bin/python3 +# +# +# this example is not usefull to find out about updated, upgradable packages +# use the depcache.py example for it (because a pkgPolicy is not used here) +# + +import apt_pkg + +apt_pkg.init() + +cache = apt_pkg.Cache() +packages = cache.packages + +uninstalled, updated, upgradable = {}, {}, {} + +for package in packages: + versions = package.version_list + if not versions: + continue + version = versions[0] + for other_version in versions: + if apt_pkg.version_compare(version.ver_str, other_version.ver_str) < 0: + version = other_version + if package.current_ver: + current = package.current_ver + if apt_pkg.version_compare(current.ver_str, version.ver_str) < 0: + upgradable[package.name] = version + break + else: + updated[package.name] = current + else: + uninstalled[package.name] = version + + +for line in (uninstalled, updated, upgradable): + print(list(line.items())[0]) |