Skip to content

Minor version missing for Debian >= 10 #332

Closed

Description

@netsandbox

For Debian >= 10 distro can't get the minor version.

This worked for Debian <= 9 at least when you have the lsb-release Debian package installed with distro.version(best=True) because lsb_release -a returned the major and minor version in the Release key:

$ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 9 (stretch)"
NAME="Debian GNU/Linux"
VERSION_ID="9"
VERSION="9 (stretch)"
VERSION_CODENAME=stretch
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 9.12 (stretch)
Release:	9.12
Codename:	stretch

But with Debian >= 10 the Release key from lsb_release -a only has the major version:

$ cat /etc/os-release 
PRETTY_NAME="Debian GNU/Linux 10 (buster)"
NAME="Debian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"

$ lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 10 (buster)
Release:	10
Codename:	buster

For Debian >= 10 the only source for the minor version is file /etc/debian_version.

The /etc/debian_version file exists for years, even on older Debian versions, with a stable format (major.minor, with the exception that Debian <= 6 has major.minor.patch).

So maybe you can consider to parse /etc/debian_version to get the minor version.

Activity

  1. HorlogeSkynet commented on Jun 3, 2022

    @HorlogeSkynet
    Member

    Hey @netsandbox,

    Whereas a small patch (see below) could bring this support to distro, one could argue that this will break version output on Debian platforms.
    From this response, "Debian version" actually corresponds to what you currently get from /etc/os-release or lsb_release.
    For "normalization" and consistency purposes, distro honors OS-RELEASE VERSION_ID attribute (if available), as it [identifies] the operating system version.

    Thanks, bye 👋


    diff --git a/src/distro/distro.py b/src/distro/distro.py
    index c731e8c..1635737 100755
    --- a/src/distro/distro.py
    +++ b/src/distro/distro.py
    @@ -895,7 +895,16 @@ class LinuxDistribution:
                 ).get("version_id", ""),
                 self.uname_attr("release"),
             ]
    -        if self.uname_attr("id").startswith("aix"):
    +        if self.id() == "debian":
    +            # On Debian, prefer debian_version file content.
    +            try:
    +                with open(
    +                    os.path.join(self.etc_dir, "debian_version"), encoding="ascii"
    +                ) as fp:
    +                    versions.insert(0, fp.readline().rstrip())
    +            except FileNotFoundError:
    +                pass
    +        elif self.uname_attr("id").startswith("aix"):
                 # On AIX platforms, prefer oslevel command output.
                 versions.insert(0, self.oslevel_info())
             version = ""
  2. self-assigned this
    on Jun 5, 2022
  3. HorlogeSkynet commented on Jun 5, 2022

    @HorlogeSkynet
    Member

    I've (maybe) came across a better patch, please see #333 🙇

  4. netsandbox commented on Jun 5, 2022

    @netsandbox
    Author

    I also think the changes in your PR are a better solution because this only changes the output for version(best=True) but not for version().

    Also applying this to Debian-like systems makes also sense.
    On Raspbian we would also get the minor version, because Raspbian behaves exactly like Debian (/etc/os-release only contains the major version and /etc/debian_version contains the minor version).
    On Devuan and Ubuntu /etc/debian_version contains bullseye/sid or bookworm/sid, but this is not a problem because versions are only considered for version(best=True) if they contain a . (dot).

  5. netsandbox commented on Jun 7, 2022

    @netsandbox
    Author

    @HorlogeSkynet thanks for your quick fix.

    Can this fix also be included in the python2.7-support branch?
    Because Ansible (and maybe other tools) still supports Python 2.7.

  6. HorlogeSkynet commented on Jun 7, 2022

    @HorlogeSkynet
    Member

    @netsandbox please see #339

  7. HorlogeSkynet commented on Jun 21, 2022

    @HorlogeSkynet
    Member

    @netsandbox #339 has been merged, you will be able to fetch latest python2.7-support branch. Cheers 👋

  8. netsandbox commented on Jun 21, 2022

    @netsandbox
    Author

    @HorlogeSkynet Thank for your help and great support.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions