I have something like this, thanks to ChatGPT, but it’s probably broken on multiple places.
I’m stopping by here as I wasn’t able to find in the documentation, that my goal is even possible.
import dnf
# Create a DNF Base object
base = dnf.Base()
# Set repository IDs
repo_ids = ['rawhide-source', 'rawhide']
# Load the repository data
base.read_all_repos()
# Enable the specified repositories
for repo_id in repo_ids:
repo = base.repos.get(repo_id)
if repo:
repo.enable()
# Initialize the sack
base.fill_sack(load_system_repo=False)
# Query packages that require "mariadb-devel" and resolve dependencies
query = base.sack.query().whatrequires('mariadb-devel').alldeps()
results = base.sack.query().filter(pkgs=query)
# Print package names that require "mariadb-devel"
for pkg in results:
print(pkg.name)
# Close the DNF Base object
base.close()
import dnf
# Create a DNF Base object
base = dnf.Base()
# Set repository IDs
repo_ids = ['rawhide-source', 'rawhide']
# Load the repository data
base.read_all_repos()
# Enable the specified repositories
for repo_id in repo_ids:
repo = base.repos.get(repo_id)
if repo:
repo.enable()
# Initialize the sack
base.fill_sack(load_system_repo=False)
# Query packages that require "mariadb-devel"
query = base.sack.query().filterm(requires=['mariadb-devel']).latest(1)
for pkg in query.run():
print(str(pkg))
Yes, I did . It provides the same API (based on the original hawkey version) for both dnf and libdnf5. Something like this should work for your usecase:
import fedrq.config
# Pass backend="libdnf5" if you're feeling adventurous :)
config = fedrq.config.get_config()
#
rq = config.get_rq("rawhide")
query = rq.query(requires=rq.query(name="mariadb-devel"), arch="src", latest=1)
for package in query:
print(package)