On Mon, 01 Nov 2021 21:52:33 -0000
"Philip Kauffman" <philip(a)kauffman.me> wrote:
The two commands you are using do different things, I think. I didn't
go deeply into the differences, but they are using different code
paths, so that is the likely explanation.
My goal is to use a python script to get all a systems repositories
in a data structure (list,dict,whatever). I've gotten most of the way
there with the below which is able to get all repositories in
/etc/yum.repos.d/*.repo. However, I can't find any reference to how
to also make python3-dnf get the RHEL repositories as well... even
though it is clearly capable of doing so (see below).
Any pointers would be greatly appreciated.
<code>
#!/usr/bin/env python3
import dnf
base = dnf.Base()
base.read_all_repos()
<code>
def read_all_repos(self, opts=None):
# :api
"""Read repositories from the main conf file and from .repo
files."""
reader = dnf.conf.read.RepoReader(self.conf, opts)
for repo in reader:
try:
self.repos.add(repo)
except dnf.exceptions.ConfigError as e:
logger.warning(e)
</code>
Yet... when I use the CLI I do get the rhel repos.
# dnf repolist rhel* | awk '{print $1}'|grep rhel
rhel-x86_64-appstream-8
rhel-x86_64-baseos-8
rhel-x86_64-codeready-builder-8
rhel-x86_64-supplementary-8
from the dnf man page
Repolist Command
Command: repolist
dnf [options] repolist [--enabled|--disabled|--all]
Depending on the exact command lists enabled, disabled or
all known repositories. Lists all enabled repositories by
default. Provides more detailed information when -v option is
used.
This command by default does not force a sync of expired
metadata. See also Metadata Synchronization.
The code for this command is in
/usr/lib/python3.10/site-packages/dnf/cli/commands/repolist.py
When I run this on my Fedora system as
dnf --all repolist
there are no rhel repositories listed. This is reasonable. So, you
must be running the above command on a system where rhel is enabled or
available in some way. I don't know the mechanism that dnf uses to
determine that. I do get a bunch of repos that aren't local to
/etc/yum.repos.d, so it is running a different command than the other.
Maybe you could use the second form from a subprocess.call, and
capture and parse the output to get all the available repos. Or a
combination of the first technique and then only the rhel repos.
The dnf python code will be in /usr/lib/python3.*/sitepackages/dnf if
you want to look at the sources, where the asterisk is the version of
python on your system, e.g. 9 or 10
You can see what files are in the package python3-dnf and where they
are installed by running
/usr/bin/rpm -q --filesbypkg python3-dnf