Skip to content

Commit 593ab0c

Browse files
evan-goodekontura
authored andcommitted
doc: Document detect_releasevers and update example
Adds dnf.rpm.detect_releasevers to the API docs and mention it is now preferred over dnf.rpm.detect_releasever. Updates examples/install_extension.py to use detect_releasevers and set the releasever_major and releasever_minor substitution variables.
1 parent 017bbab commit 593ab0c

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

doc/api_rpm.rst

+8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,14 @@
2727

2828
Returns ``None`` if the information can not be determined (perhaps because the tree has no RPMDB).
2929

30+
.. function:: detect_releasevers(installroot)
31+
32+
Returns a tuple of the release name, overridden major release, and overridden minor release of the distribution of the tree rooted at `installroot`. The function uses information from RPMDB found under the tree. The major and minor release versions are usually derived from the release version by splitting it on the first ``.``, but distributions can override the derived major and minor versions. It's preferred to use ``detect_releasevers`` over ``detect_releasever``; if you use the latter, you will not be aware of distribution overrides for the major and minor release versions.
33+
34+
Returns ``(None, None, None)`` if the information can not be determined (perhaps because the tree has no RPMDB).
35+
36+
If the distribution does not override the release major version, then the second item of the returned tuple will be ``None``. Likewise, if the release minor version is not overridden, the third return value will be ``None``.
37+
3038
.. function:: basearch(arch)
3139

3240
Return base architecture of the processor based on `arch` type given. E.g. when `arch` i686 is given then the returned value will be i386.

doc/examples/install_extension.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,12 @@
3232

3333
with dnf.Base() as base:
3434
# Substitutions are needed for correct interpretation of repo files.
35-
RELEASEVER = dnf.rpm.detect_releasever(base.conf.installroot)
35+
RELEASEVER, MAJOR, MINOR = dnf.rpm.detect_releasever(base.conf.installroot)
3636
base.conf.substitutions['releasever'] = RELEASEVER
37+
if MAJOR is not None:
38+
base.conf.substitutions['releasever_major'] = MAJOR
39+
if MINOR is not None:
40+
base.conf.substitutions['releasever_minor'] = MINOR
3741
# Repositories are needed if we want to install anything.
3842
base.read_all_repos()
3943
# A sack is required by marking methods and dependency resolving.

0 commit comments

Comments
 (0)