summaryrefslogtreecommitdiffstats
path: root/doc/source/examples/missing-deps.py
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 18:07:41 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-15 18:07:41 +0000
commit76926159194e180003aa78de97e5f287bf4325a5 (patch)
tree2cea7245cdc3f66355900c820c145eba90598766 /doc/source/examples/missing-deps.py
parentInitial commit. (diff)
downloadpython-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/source/examples/missing-deps.py')
-rwxr-xr-xdoc/source/examples/missing-deps.py59
1 files changed, 59 insertions, 0 deletions
diff --git a/doc/source/examples/missing-deps.py b/doc/source/examples/missing-deps.py
new file mode 100755
index 0000000..c3c56b8
--- /dev/null
+++ b/doc/source/examples/missing-deps.py
@@ -0,0 +1,59 @@
+#!/usr/bin/python3
+"""Check the archive for missing dependencies"""
+import apt_pkg
+
+
+def fmt_dep(dep):
+ """Format a Dependency object [of apt_pkg] as a string."""
+ ret = dep.target_pkg.name
+ if dep.target_ver:
+ ret += f" ({dep.comp_type} {dep.target_ver})"
+ return ret
+
+
+def check_version(pkgver):
+ """Check the version of the package"""
+ missing = []
+
+ for or_group in pkgver.depends_list.get(
+ "Pre-Depends", []
+ ) + pkgver.depends_list.get("Depends", []):
+ if not any(dep.all_targets() for dep in or_group):
+ # If none of the or-choices can be satisfied, add it to missing
+ missing.append(or_group)
+
+ if missing:
+ print("Package:", pkgver.parent_pkg.name)
+ print("Version:", pkgver.ver_str)
+ print("Missing:")
+ print(
+ ", ".join(" | ".join(fmt_dep(dep) for dep in or_group))
+ for or_group in missing
+ )
+ print()
+
+
+def main():
+ """The main function."""
+ apt_pkg.init_config()
+ apt_pkg.init_system()
+
+ cache = apt_pkg.Cache()
+
+ for pkg in sorted(cache.packages, key=lambda pkg: pkg.name):
+ # pkg is from a list of packages, sorted by name.
+ for version in pkg.version_list:
+ # Check every version
+ for pfile, _ in version.file_list:
+ if (
+ pfile.origin == "Debian"
+ and pfile.component == "main"
+ and pfile.archive == "unstable"
+ ):
+ # We only want packages from Debian unstable main.
+ check_version(version)
+ break
+
+
+if __name__ == "__main__":
+ main()