Qucs-S S-parameter Viewer & RF Synthesis Tools
Loading...
Searching...
No Matches
Classes | Functions | Variables
pip._vendor.distro.distro Namespace Reference

Classes

class  cached_property
 
class  InfoDict
 
class  LinuxDistribution
 
class  VersionDict
 

Functions

Tuple[str, str, str] linux_distribution (bool full_distribution_name=True)
 
str id ()
 
str name (bool pretty=False)
 
str version (bool pretty=False, bool best=False)
 
Tuple[str, str, str] version_parts (bool best=False)
 
str major_version (bool best=False)
 
str minor_version (bool best=False)
 
str build_number (bool best=False)
 
str like ()
 
str codename ()
 
InfoDict info (bool pretty=False, bool best=False)
 
Dict[str, str] os_release_info ()
 
Dict[str, str] lsb_release_info ()
 
Dict[str, str] distro_release_info ()
 
Dict[str, str] uname_info ()
 
str os_release_attr (str attribute)
 
str lsb_release_attr (str attribute)
 
str distro_release_attr (str attribute)
 
str uname_attr (str attribute)
 
None main ()
 

Variables

 TypedDict = dict
 
 _UNIXCONFDIR = os.environ.get("UNIXCONFDIR", "/etc")
 
 _UNIXUSRLIBDIR = os.environ.get("UNIXUSRLIBDIR", "/usr/lib")
 
str _OS_RELEASE_BASENAME = "os-release"
 
dict NORMALIZED_OS_ID
 
dict NORMALIZED_LSB_ID
 
dict NORMALIZED_DISTRO_ID
 
 _DISTRO_RELEASE_CONTENT_REVERSED_PATTERN
 
 _DISTRO_RELEASE_BASENAME_PATTERN = re.compile(r"(\w+)[-_](release|version)$")
 
list _DISTRO_RELEASE_BASENAMES
 
tuple _DISTRO_RELEASE_IGNORE_BASENAMES
 
 _distro = LinuxDistribution()
 

Detailed Description

The ``distro`` package (``distro`` stands for Linux Distribution) provides
information about the Linux distribution it runs on, such as a reliable
machine-readable distro ID, or version information.

It is the recommended replacement for Python's original
:py:func:`platform.linux_distribution` function, but it provides much more
functionality. An alternative implementation became necessary because Python
3.5 deprecated this function, and Python 3.8 removed it altogether. Its
predecessor function :py:func:`platform.dist` was already deprecated since
Python 2.6 and removed in Python 3.8. Still, there are many cases in which
access to OS distribution information is needed. See `Python issue 1322
<https://bugs.python.org/issue1322>`_ for more information.

Function Documentation

◆ build_number()

str pip._vendor.distro.distro.build_number ( bool   best = False)
Return the build number of the current OS distribution, as a string,
if provided.
Otherwise, the empty string is returned. The build number is the third part
of the dot-separated version string.

For a description of the *best* parameter, see the :func:`distro.version`
method.

◆ codename()

str pip._vendor.distro.distro.codename ( )
Return the codename for the release of the current OS distribution,
as a string.

If the distribution does not have a codename, an empty string is returned.

Note that the returned codename is not always really a codename. For
example, openSUSE returns "x86_64". This function does not handle such
cases in any special way and just returns the string it finds, if any.

**Lookup hierarchy:**

* the codename within the "VERSION" attribute of the os-release file, if
  provided,

* the value of the "Codename" attribute returned by the lsb_release
  command,

* the value of the "<codename>" field of the distro release file.

◆ distro_release_attr()

str pip._vendor.distro.distro.distro_release_attr ( str  attribute)
Return a single named information item from the distro release file
data source of the current OS distribution.

Parameters:

* ``attribute`` (string): Key of the information item.

Returns:

* (string): Value of the information item, if the item exists.
  The empty string, if the item does not exist.

See `distro release file`_ for details about these information items.

◆ distro_release_info()

Dict[str, str] pip._vendor.distro.distro.distro_release_info ( )
Return a dictionary containing key-value pairs for the information items
from the distro release file data source of the current OS distribution.

See `distro release file`_ for details about these information items.

◆ id()

str pip._vendor.distro.distro.id ( )
Return the distro ID of the current distribution, as a
machine-readable string.

For a number of OS distributions, the returned distro ID value is
*reliable*, in the sense that it is documented and that it does not change
across releases of the distribution.

This package maintains the following reliable distro ID values:

==============  =========================================
Distro ID       Distribution
==============  =========================================
"ubuntu"        Ubuntu
"debian"        Debian
"rhel"          RedHat Enterprise Linux
"centos"        CentOS
"fedora"        Fedora
"sles"          SUSE Linux Enterprise Server
"opensuse"      openSUSE
"amzn"          Amazon Linux
"arch"          Arch Linux
"buildroot"     Buildroot
"cloudlinux"    CloudLinux OS
"exherbo"       Exherbo Linux
"gentoo"        GenToo Linux
"ibm_powerkvm"  IBM PowerKVM
"kvmibm"        KVM for IBM z Systems
"linuxmint"     Linux Mint
"mageia"        Mageia
"mandriva"      Mandriva Linux
"parallels"     Parallels
"pidora"        Pidora
"raspbian"      Raspbian
"oracle"        Oracle Linux (and Oracle Enterprise Linux)
"scientific"    Scientific Linux
"slackware"     Slackware
"xenserver"     XenServer
"openbsd"       OpenBSD
"netbsd"        NetBSD
"freebsd"       FreeBSD
"midnightbsd"   MidnightBSD
"rocky"         Rocky Linux
"aix"           AIX
"guix"          Guix System
==============  =========================================

If you have a need to get distros for reliable IDs added into this set,
or if you find that the :func:`distro.id` function returns a different
distro ID for one of the listed distros, please create an issue in the
`distro issue tracker`_.

**Lookup hierarchy and transformations:**

First, the ID is obtained from the following sources, in the specified
order. The first available and non-empty value is used:

* the value of the "ID" attribute of the os-release file,

* the value of the "Distributor ID" attribute returned by the lsb_release
  command,

* the first part of the file name of the distro release file,

The so determined ID value then passes the following transformations,
before it is returned by this method:

* it is translated to lower case,

* blanks (which should not be there anyway) are translated to underscores,

* a normalization of the ID is performed, based upon
  `normalization tables`_. The purpose of this normalization is to ensure
  that the ID is as reliable as possible, even across incompatible changes
  in the OS distributions. A common reason for an incompatible change is
  the addition of an os-release file, or the addition of the lsb_release
  command, with ID values that differ from what was previously determined
  from the distro release file name.

◆ info()

InfoDict pip._vendor.distro.distro.info ( bool   pretty = False,
bool   best = False 
)
Return certain machine-readable information items about the current OS
distribution in a dictionary, as shown in the following example:

.. sourcecode:: python

    {
        'id': 'rhel',
        'version': '7.0',
        'version_parts': {
            'major': '7',
            'minor': '0',
            'build_number': ''
        },
        'like': 'fedora',
        'codename': 'Maipo'
    }

The dictionary structure and keys are always the same, regardless of which
information items are available in the underlying data sources. The values
for the various keys are as follows:

* ``id``:  The result of :func:`distro.id`.

* ``version``:  The result of :func:`distro.version`.

* ``version_parts -> major``:  The result of :func:`distro.major_version`.

* ``version_parts -> minor``:  The result of :func:`distro.minor_version`.

* ``version_parts -> build_number``:  The result of
  :func:`distro.build_number`.

* ``like``:  The result of :func:`distro.like`.

* ``codename``:  The result of :func:`distro.codename`.

For a description of the *pretty* and *best* parameters, see the
:func:`distro.version` method.

◆ like()

str pip._vendor.distro.distro.like ( )
Return a space-separated list of distro IDs of distributions that are
closely related to the current OS distribution in regards to packaging
and programming interfaces, for example distributions the current
distribution is a derivative from.

**Lookup hierarchy:**

This information item is only provided by the os-release file.
For details, see the description of the "ID_LIKE" attribute in the
`os-release man page
<http://www.freedesktop.org/software/systemd/man/os-release.html>`_.

◆ linux_distribution()

Tuple[str, str, str] pip._vendor.distro.distro.linux_distribution ( bool   full_distribution_name = True)
.. deprecated:: 1.6.0

    :func:`distro.linux_distribution()` is deprecated. It should only be
    used as a compatibility shim with Python's
    :py:func:`platform.linux_distribution()`. Please use :func:`distro.id`,
    :func:`distro.version` and :func:`distro.name` instead.

Return information about the current OS distribution as a tuple
``(id_name, version, codename)`` with items as follows:

* ``id_name``:  If *full_distribution_name* is false, the result of
  :func:`distro.id`. Otherwise, the result of :func:`distro.name`.

* ``version``:  The result of :func:`distro.version`.

* ``codename``:  The extra item (usually in parentheses) after the
  os-release version number, or the result of :func:`distro.codename`.

The interface of this function is compatible with the original
:py:func:`platform.linux_distribution` function, supporting a subset of
its parameters.

The data it returns may not exactly be the same, because it uses more data
sources than the original function, and that may lead to different data if
the OS distribution is not consistent across multiple data sources it
provides (there are indeed such distributions ...).

Another reason for differences is the fact that the :func:`distro.id`
method normalizes the distro ID string to a reliable machine-readable value
for a number of popular OS distributions.

◆ lsb_release_attr()

str pip._vendor.distro.distro.lsb_release_attr ( str  attribute)
Return a single named information item from the lsb_release command output
data source of the current OS distribution.

Parameters:

* ``attribute`` (string): Key of the information item.

Returns:

* (string): Value of the information item, if the item exists.
  The empty string, if the item does not exist.

See `lsb_release command output`_ for details about these information
items.

◆ lsb_release_info()

Dict[str, str] pip._vendor.distro.distro.lsb_release_info ( )
Return a dictionary containing key-value pairs for the information items
from the lsb_release command data source of the current OS distribution.

See `lsb_release command output`_ for details about these information
items.

◆ major_version()

str pip._vendor.distro.distro.major_version ( bool   best = False)
Return the major version of the current OS distribution, as a string,
if provided.
Otherwise, the empty string is returned. The major version is the first
part of the dot-separated version string.

For a description of the *best* parameter, see the :func:`distro.version`
method.

◆ minor_version()

str pip._vendor.distro.distro.minor_version ( bool   best = False)
Return the minor version of the current OS distribution, as a string,
if provided.
Otherwise, the empty string is returned. The minor version is the second
part of the dot-separated version string.

For a description of the *best* parameter, see the :func:`distro.version`
method.

◆ name()

str pip._vendor.distro.distro.name ( bool   pretty = False)
Return the name of the current OS distribution, as a human-readable
string.

If *pretty* is false, the name is returned without version or codename.
(e.g. "CentOS Linux")

If *pretty* is true, the version and codename are appended.
(e.g. "CentOS Linux 7.1.1503 (Core)")

**Lookup hierarchy:**

The name is obtained from the following sources, in the specified order.
The first available and non-empty value is used:

* If *pretty* is false:

  - the value of the "NAME" attribute of the os-release file,

  - the value of the "Distributor ID" attribute returned by the lsb_release
    command,

  - the value of the "<name>" field of the distro release file.

* If *pretty* is true:

  - the value of the "PRETTY_NAME" attribute of the os-release file,

  - the value of the "Description" attribute returned by the lsb_release
    command,

  - the value of the "<name>" field of the distro release file, appended
    with the value of the pretty version ("<version_id>" and "<codename>"
    fields) of the distro release file, if available.

◆ os_release_attr()

str pip._vendor.distro.distro.os_release_attr ( str  attribute)
Return a single named information item from the os-release file data source
of the current OS distribution.

Parameters:

* ``attribute`` (string): Key of the information item.

Returns:

* (string): Value of the information item, if the item exists.
  The empty string, if the item does not exist.

See `os-release file`_ for details about these information items.

◆ os_release_info()

Dict[str, str] pip._vendor.distro.distro.os_release_info ( )
Return a dictionary containing key-value pairs for the information items
from the os-release file data source of the current OS distribution.

See `os-release file`_ for details about these information items.

◆ uname_attr()

str pip._vendor.distro.distro.uname_attr ( str  attribute)
Return a single named information item from the distro release file
data source of the current OS distribution.

Parameters:

* ``attribute`` (string): Key of the information item.

Returns:

* (string): Value of the information item, if the item exists.
            The empty string, if the item does not exist.

◆ uname_info()

Dict[str, str] pip._vendor.distro.distro.uname_info ( )
Return a dictionary containing key-value pairs for the information items
from the distro release file data source of the current OS distribution.

◆ version()

str pip._vendor.distro.distro.version ( bool   pretty = False,
bool   best = False 
)
Return the version of the current OS distribution, as a human-readable
string.

If *pretty* is false, the version is returned without codename (e.g.
"7.0").

If *pretty* is true, the codename in parenthesis is appended, if the
codename is non-empty (e.g. "7.0 (Maipo)").

Some distributions provide version numbers with different precisions in
the different sources of distribution information. Examining the different
sources in a fixed priority order does not always yield the most precise
version (e.g. for Debian 8.2, or CentOS 7.1).

Some other distributions may not provide this kind of information. In these
cases, an empty string would be returned. This behavior can be observed
with rolling releases distributions (e.g. Arch Linux).

The *best* parameter can be used to control the approach for the returned
version:

If *best* is false, the first non-empty version number in priority order of
the examined sources is returned.

If *best* is true, the most precise version number out of all examined
sources is returned.

**Lookup hierarchy:**

In all cases, the version number is obtained from the following sources.
If *best* is false, this order represents the priority order:

* the value of the "VERSION_ID" attribute of the os-release file,
* the value of the "Release" attribute returned by the lsb_release
  command,
* the version number parsed from the "<version_id>" field of the first line
  of the distro release file,
* the version number parsed from the "PRETTY_NAME" attribute of the
  os-release file, if it follows the format of the distro release files.
* the version number parsed from the "Description" attribute returned by
  the lsb_release command, if it follows the format of the distro release
  files.

◆ version_parts()

Tuple[str, str, str] pip._vendor.distro.distro.version_parts ( bool   best = False)
Return the version of the current OS distribution as a tuple
``(major, minor, build_number)`` with items as follows:

* ``major``:  The result of :func:`distro.major_version`.

* ``minor``:  The result of :func:`distro.minor_version`.

* ``build_number``:  The result of :func:`distro.build_number`.

For a description of the *best* parameter, see the :func:`distro.version`
method.

Variable Documentation

◆ _DISTRO_RELEASE_BASENAMES

list pip._vendor.distro.distro._DISTRO_RELEASE_BASENAMES
protected
Initial value:
1= [
2 "SuSE-release",
3 "arch-release",
4 "base-release",
5 "centos-release",
6 "fedora-release",
7 "gentoo-release",
8 "mageia-release",
9 "mandrake-release",
10 "mandriva-release",
11 "mandrivalinux-release",
12 "manjaro-release",
13 "oracle-release",
14 "redhat-release",
15 "rocky-release",
16 "sl-release",
17 "slackware-version",
18]

◆ _DISTRO_RELEASE_CONTENT_REVERSED_PATTERN

pip._vendor.distro.distro._DISTRO_RELEASE_CONTENT_REVERSED_PATTERN
protected
Initial value:
1= re.compile(
2 r"(?:[^)]*\‍)(.*)\‍()? *(?:STL )?([\d.+\-a-z]*\d) *(?:esaeler *)?(.+)"
3)

◆ _DISTRO_RELEASE_IGNORE_BASENAMES

tuple pip._vendor.distro.distro._DISTRO_RELEASE_IGNORE_BASENAMES
protected
Initial value:
1= (
2 "debian_version",
3 "lsb-release",
4 "oem-release",
5 _OS_RELEASE_BASENAME,
6 "system-release",
7 "plesk-release",
8 "iredmail-release",
9)

◆ NORMALIZED_DISTRO_ID

dict pip._vendor.distro.distro.NORMALIZED_DISTRO_ID
Initial value:
1= {
2 "redhat": "rhel", # RHEL 6.x, 7.x
3}

◆ NORMALIZED_LSB_ID

dict pip._vendor.distro.distro.NORMALIZED_LSB_ID
Initial value:
1= {
2 "enterpriseenterpriseas": "oracle", # Oracle Enterprise Linux 4
3 "enterpriseenterpriseserver": "oracle", # Oracle Linux 5
4 "redhatenterpriseworkstation": "rhel", # RHEL 6, 7 Workstation
5 "redhatenterpriseserver": "rhel", # RHEL 6, 7 Server
6 "redhatenterprisecomputenode": "rhel", # RHEL 6 ComputeNode
7}

◆ NORMALIZED_OS_ID

dict pip._vendor.distro.distro.NORMALIZED_OS_ID
Initial value:
1= {
2 "ol": "oracle", # Oracle Linux
3 "opensuse-leap": "opensuse", # Newer versions of OpenSuSE report as opensuse-leap
4}