HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //home/arjun/python-apt/doc/examples/dependant-pkgs.py
#!/usr/bin/python3

import sys

import apt

pkgs = set()
cache = apt.Cache()
for pkg in cache:
    candver = cache._depcache.get_candidate_ver(pkg._pkg)
    if candver is None:
        continue
    dependslist = candver.depends_list
    for dep in list(dependslist.keys()):
        # get the list of each dependency object
        for depVerList in dependslist[dep]:
            for z in depVerList:
                # get all TargetVersions of
                # the dependency object
                for tpkg in z.all_targets():
                    if sys.argv[1] == tpkg.parent_pkg.name:
                        pkgs.add(pkg.name)

main = set()
universe = set()
for pkg in pkgs:
    cand = cache[pkg].candidate
    if "universe" in cand.section:
        universe.add(cand.source_name)
    else:
        main.add(cand.source_name)

print("main:")
print("\n".join(sorted(main)))
print()

print("universe:")
print("\n".join(sorted(universe)))