Top Banner
Linux Distribution - a Linux OS platform information API Release 1.3.0 Nir Cohen, Andreas Maier Sep 04, 2018
37

Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Mar 22, 2019

Download

Documents

doankien
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platforminformation API

Release 1.3.0

Nir Cohen, Andreas Maier

Sep 04, 2018

Page 2: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian
Page 3: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Contents

1 Overview and motivation 3

2 Compatibility 5

3 Data sources 7

4 Access to the information 9

5 Consolidated accessor functions 11

6 Single source accessor functions 17

7 LinuxDistribution class 19

8 Normalization tables 23

9 Os-release file 25

10 Lsb_release command output 27

11 Distro release file 29

Python Module Index 31

i

Page 4: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

ii

Page 5: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

Official distro repository: distro official repo

Contents 1

Page 6: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

2 Contents

Page 7: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

CHAPTER 1

Overview and motivation

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

It is the recommended replacement for Python’s original platform.linux_distribution() function, but itprovides much more functionality. An alternative implementation became necessary because Python 3.5 deprecatedthis function, and Python 3.8 will remove it altogether. Its predecessor function platform.dist() was alreadydeprecated since Python 2.6 and will also be removed in Python 3.8. Still, there are many cases in which access to OSdistribution information is needed. See Python issue 1322 for more information.

If you want to jump into the API description right away, read about the consolidated accessor functions.

3

Page 8: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

4 Chapter 1. Overview and motivation

Page 9: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

CHAPTER 2

Compatibility

The distro package is supported on Python 2.7, 3.4+ and PyPy, and on any Linux or *BSD distribution that providesone or more of the data sources used by this package.

This package is tested on Python 2.7, 3.4+ and PyPy, with test data that mimics the exact behavior of the data sourcesof a number of Linux distributions.

If you want to add test data for more distributions, please create an issue in the distro issue tracker and provide thefollowing information in the issue:

• The content of the /etc/os-release file, if any.

• The file names and content of the /etc/*release and /etc/*version files, if any.

• The output of the command: lsb_release -a, if available.

• The file names and content of any other files you are aware of that provide useful information about the distro.

There are already some open issues on missing test data.

5

Page 10: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

6 Chapter 2. Compatibility

Page 11: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

CHAPTER 3

Data sources

The distro package implements a robust and inclusive way of retrieving the information about a Linux distributionbased on new standards and old methods, namely from these data sources:

• The os-release file, if present.

• The lsb_release command output, if the lsb_release command is available.

• The distro release file, if present.

• The ‘uname command output‘_, if present.

7

Page 12: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

8 Chapter 3. Data sources

Page 13: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

CHAPTER 4

Access to the information

This package provides three ways to access the information about a Linux distribution:

• Consolidated accessor functions

These are module-global functions that take into account all data sources in a priority order, and that returninformation about the current Linux distribution.

These functions should be the normal way to access the information.

The precedence of data sources is applied for each information item separately. Therefore, it is possible that notall information items returned by these functions come from the same data source. For example, on a distributionthat has an lsb_release command that returns the “Distributor ID” field but not the “Codename” field, and thathas a distro release file that specifies a codename inside, the distro ID will come from the lsb_release command(because it has higher precedence), and the codename will come from the distro release file (because it is notprovided by the lsb_release command).

Examples: distro.id() for retrieving the distro ID, or ld.info() to get the machine-readable part ofthe information in a more aggregated way, or distro.linux_distribution() with an interface thatis compatible to the original platform.linux_distribution() function, supporting a subset of itsparameters.

• Single source accessor functions

These are module-global functions that take into account a single data source, and that return information aboutthe current Linux distribution.

They are useful for distributions that provide multiple inconsistent data sources, or for retrieving informationitems that are not provided by the consolidated accessor functions.

Examples: distro.os_release_attr() for retrieving a single information item from the os-release datasource, or distro.lsb_release_info() for retrieving all information items from the lsb_release com-mand output data source.

• LinuxDistribution class

The distro.LinuxDistribution class provides the main code of this package.

9

Page 14: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

This package contains a private module-global distro.LinuxDistribution instance with default initial-ization arguments, that is used by the consolidated and single source accessor functions.

A user-defined instance of the distro.LinuxDistribution class allows specifying the path names of theos-release file and distro release file and whether the lsb_release command should be used or not. That is usefulfor example when the distribution information from a chrooted environment is to be retrieved, or when a distrohas multiple distro release files and the default algorithm uses the wrong one.

10 Chapter 4. Access to the information

Page 15: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

CHAPTER 5

Consolidated accessor functions

This section describes the consolidated accessor functions. See access to the information for a discussion of thedifferent kinds of accessor functions.

distro.linux_distribution(full_distribution_name=True)Return information about the current OS distribution as a tuple (id_name, version, codename) withitems as follows:

• id_name: If full_distribution_name is false, the result of distro.id(). Otherwise, the result ofdistro.name().

• version: The result of distro.version().

• codename: The result of distro.codename().

The interface of this function is compatible with the original platform.linux_distribution() func-tion, 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 distro.id() method normalizes the distro ID string to areliable machine-readable value for a number of popular OS distributions.

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 andthat it does not change across releases of the distribution.

This package maintains the following reliable distro ID values:

11

Page 16: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

Distro ID Distribution“ubuntu” Ubuntu“debian” Debian“rhel” RedHat Enterprise Linux“centos” CentOS“fedora” Fedora“sles” SUSE Linux Enterprise Server“opensuse” openSUSE“amazon” Amazon Linux“arch” Arch Linux“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

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

Lookup hierarchy and transformations:

First, the ID is obtained from the following sources, in the specified order. The first available and non-emptyvalue 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 normalizationis 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 thelsb_release command, with ID values that differ from what was previously determined from the distrorelease file name.

12 Chapter 5. Consolidated accessor functions

Page 17: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

distro.name(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 valueis 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.

distro.version(pretty=False, 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 distributioninformation. Examining the different sources in a fixed priority order does not always yield the most preciseversion (e.g. for Debian 8.2, or CentOS 7.1).

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 thepriority 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 theformat of the distro release files.

• the version number parsed from the “Description” attribute returned by the lsb_release command, if itfollows the format of the distro release files.

distro.version_parts(best=False)Return the version of the current OS distribution as a tuple (major, minor, build_number) with itemsas follows:

• major: The result of distro.major_version().

13

Page 18: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

• minor: The result of distro.minor_version().

• build_number: The result of distro.build_number().

For a description of the best parameter, see the distro.version() method.

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

For a description of the best parameter, see the distro.version() method.

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

For a description of the best parameter, see the distro.version() method.

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

For a description of the best parameter, see the distro.version() method.

distro.like()Return a space-separated list of distro IDs of distributions that are closely related to the current OS distributionin regards to packaging and programming interfaces, for example distributions the current distribution is aderivative 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.

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.info(pretty=False, best=False)Return certain machine-readable information items about the current OS distribution in a dictionary, as shownin the following example:

'id': 'rhel','version': '7.0','version_parts':

'major': '7','minor': '0','build_number': ''

,'like': 'fedora',

(continues on next page)

14 Chapter 5. Consolidated accessor functions

Page 19: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

(continued from previous page)

'codename': 'Maipo'

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

• id: The result of distro.id().

• version: The result of distro.version().

• version_parts -> major: The result of distro.major_version().

• version_parts -> minor: The result of distro.minor_version().

• version_parts -> build_number: The result of distro.build_number().

• like: The result of distro.like().

• codename: The result of distro.codename().

For a description of the pretty and best parameters, see the distro.version() method.

15

Page 20: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

16 Chapter 5. Consolidated accessor functions

Page 21: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

CHAPTER 6

Single source accessor functions

This section describes the single source accessor functions. See access to the information for a discussion of thedifferent kinds of accessor functions.

distro.os_release_info()Return a dictionary containing key-value pairs for the information items from the os-release file data source ofthe current OS distribution.

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

distro.lsb_release_info()Return a dictionary containing key-value pairs for the information items from the lsb_release command datasource of the current OS distribution.

See lsb_release command output for details about these information items.

distro.distro_release_info()Return a dictionary containing key-value pairs for the information items from the distro release file data sourceof the current OS distribution.

See distro release file for details about these information items.

distro.os_release_attr(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.

distro.lsb_release_attr(attribute)Return a single named information item from the lsb_release command output data source of the current OSdistribution.

Parameters:

17

Page 22: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

• 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.

distro.distro_release_attr(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.

18 Chapter 6. Single source accessor functions

Page 23: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

CHAPTER 7

LinuxDistribution class

This section describes the access via the distro.LinuxDistribution class. See access to the information fora discussion of the different kinds of accessor functions.

class distro.LinuxDistribution(include_lsb=True, os_release_file=”, distro_release_file=”, in-clude_uname=True)

Provides information about a OS distribution.

This package creates a private module-global instance of this class with default initialization arguments, that isused by the consolidated accessor functions and single source accessor functions. By using default initializationarguments, that module-global instance returns data about the current OS distribution (i.e. the distro this packageruns on).

Normally, it is not necessary to create additional instances of this class. However, in situations where controlis needed over the exact data sources that are used, instances of this class can be created with a specific distrorelease file, or a specific os-release file, or without invoking the lsb_release command.

The initialization method of this class gathers information from the available data sources, and stores that inprivate instance attributes. Subsequent access to the information items uses these private instance attributes, sothat the data sources are read only once.

Parameters:

• include_lsb (bool): Controls whether the lsb_release command output is included as a data source.

If the lsb_release command is not available in the program execution path, the data source for thelsb_release command will be empty.

• os_release_file (string): The path name of the os-release file that is to be used as a data source.

An empty string (the default) will cause the default path name to be used (see os-release file for details).

If the specified or defaulted os-release file does not exist, the data source for the os-release file will beempty.

• distro_release_file (string): The path name of the distro release file that is to be used as a datasource.

19

Page 24: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

An empty string (the default) will cause a default search algorithm to be used (see distro release file fordetails).

If the specified distro release file does not exist, or if no default distro release file can be found, the datasource for the distro release file will be empty.

• include_name (bool): Controls whether uname command output is included as a data source. If theuname command is not available in the program execution path the data source for the uname commandwill be empty.

Public instance attributes:

• os_release_file (string): The path name of the os-release file that is actually used as a data source.The empty string if no distro release file is used as a data source.

• distro_release_file (string): The path name of the distro release file that is actually used as a datasource. The empty string if no distro release file is used as a data source.

• include_lsb (bool): The result of the include_lsb parameter. This controls whether the lsb infor-mation will be loaded.

• include_uname (bool): The result of the include_uname parameter. This controls whether theuname information will be loaded.

Raises:

• IOError: Some I/O issue with an os-release file or distro release file.

• subprocess.CalledProcessError: The lsb_release command had some issue (other than notbeing available in the program execution path).

• UnicodeError: A data source has unexpected characters or uses an unexpected encoding.

linux_distribution(full_distribution_name=True)Return information about the OS distribution that is compatible with Python’s platform.linux_distribution(), supporting a subset of its parameters.

For details, see distro.linux_distribution().

id()Return the distro ID of the OS distribution, as a string.

For details, see distro.id().

name(pretty=False)Return the name of the OS distribution, as a string.

For details, see distro.name().

version(pretty=False, best=False)Return the version of the OS distribution, as a string.

For details, see distro.version().

version_parts(best=False)Return the version of the OS distribution, as a tuple of version numbers.

For details, see distro.version_parts().

major_version(best=False)Return the major version number of the current distribution.

For details, see distro.major_version().

20 Chapter 7. LinuxDistribution class

Page 25: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

minor_version(best=False)Return the minor version number of the current distribution.

For details, see distro.minor_version().

build_number(best=False)Return the build number of the current distribution.

For details, see distro.build_number().

like()Return the IDs of distributions that are like the OS distribution.

For details, see distro.like().

codename()Return the codename of the OS distribution.

For details, see distro.codename().

info(pretty=False, best=False)Return certain machine-readable information about the OS distribution.

For details, see distro.info().

os_release_info()Return a dictionary containing key-value pairs for the information items from the os-release file data sourceof the OS distribution.

For details, see distro.os_release_info().

lsb_release_info()Return a dictionary containing key-value pairs for the information items from the lsb_release commanddata source of the OS distribution.

For details, see distro.lsb_release_info().

distro_release_info()Return a dictionary containing key-value pairs for the information items from the distro release file datasource of the OS distribution.

For details, see distro.distro_release_info().

uname_info()Return a dictionary containing key-value pairs for the information items from the uname command datasource of the OS distribution.

For details, see distro.uname_info().

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

For details, see distro.os_release_attr().

lsb_release_attr(attribute)Return a single named information item from the lsb_release command output data source of the OSdistribution.

For details, see distro.lsb_release_attr().

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

For details, see distro.distro_release_attr().

21

Page 26: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

uname_attr(attribute)Return a single named information item from the uname command output data source of the OS distribu-tion.

For details, see distro.uname_release_attr().

22 Chapter 7. LinuxDistribution class

Page 27: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

CHAPTER 8

Normalization tables

These translation tables are used to normalize the parsed distro ID values into reliable IDs. See distro.id() fordetails.

They are documented in order to show for which distros a normalization is currently defined.

As a quick fix, these tables can also be extended by the user by appending new entries, should the need arise. If youhave a need to get these tables extended, please make an according request in the distro issue tracker.

distro.NORMALIZED_OS_ID = Translation table for normalizing the “ID” attribute defined in os-release files, for use by the distro.id()method.

• Key: Value as defined in the os-release file, translated to lower case, with blanks translated to underscores.

• Value: Normalized value.

distro.NORMALIZED_LSB_ID = 'enterpriseenterprise': 'oracle', 'redhatenterpriseserver': 'rhel', 'redhatenterpriseworkstation': 'rhel'Translation table for normalizing the “Distributor ID” attribute returned by the lsb_release command, for use bythe distro.id() method.

• Key: Value as returned by the lsb_release command, translated to lower case, with blanks translated tounderscores.

• Value: Normalized value.

distro.NORMALIZED_DISTRO_ID = 'redhat': 'rhel'Translation table for normalizing the distro ID derived from the file name of distro release files, for use by thedistro.id() method.

• Key: Value as derived from the file name of a distro release file, translated to lower case, with blankstranslated to underscores.

• Value: Normalized value.

23

Page 28: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

24 Chapter 8. Normalization tables

Page 29: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

CHAPTER 9

Os-release file

The os-release file is looked up using the path name /etc/os-release. Its optional additional location /usr/lib/os-release is ignored.

The os-release file is expected to be encoded in UTF-8.

It is parsed using the standard Python shlex package, which treats it like a shell script.

The attribute names found in the file are translated to lower case and then become the keys of the informa-tion items from the os-release file data source. These keys can be used to retrieve single items with thedistro.os_release_attr() function, and they are also used as keys in the dictionary returned by distro.os_release_info().

The attribute values found in the file are processed using shell rules (e.g. for whitespace, escaping, and quoting) beforethey become the values of the information items from the os-release file data source.

If the attribute “VERSION” is found in the file, the distro codename is extracted from its value if it can be found there.If a codename is found, it becomes an additional information item with key “codename”.

See the os-release man page for a list of possible attributes in the file.

Examples:

1. The following os-release file content:

NAME='Ubuntu'VERSION="14.04.3 LTS, Trusty Tahr"ID=ubuntuID_LIKE=debianPRETTY_NAME="Ubuntu 14.04.3 LTS"VERSION_ID="14.04"HOME_URL="http://www.ubuntu.com/"SUPPORT_URL="http://help.ubuntu.com/"BUG_REPORT_URL="http://bugs.launchpad.net/ubuntu/"

results in these information items:

25

Page 30: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

Key Valuename “Ubuntu”version “14.04.3 LTS, Trusty Tahr”id “ubuntu”id_like “debian”pretty_name “Ubuntu 14.04.3 LTS”version_id “14.04”home_url “http://www.ubuntu.com/”support_url “http://help.ubuntu.com/”bug_report_url “http://bugs.launchpad.net/ubuntu/”codename “Trusty Tahr”

2. The following os-release file content:

NAME="Red Hat Enterprise Linux Server"VERSION="7.0 (Maipo)"ID="rhel"ID_LIKE="fedora"VERSION_ID="7.0"PRETTY_NAME="Red Hat Enterprise Linux Server 7.0 (Maipo)"ANSI_COLOR="0;31"CPE_NAME="cpe:/o:redhat:enterprise_linux:7.0:GA:server"HOME_URL="https://www.redhat.com/"BUG_REPORT_URL="https://bugzilla.redhat.com/"

REDHAT_BUGZILLA_PRODUCT="Red Hat Enterprise Linux 7"REDHAT_BUGZILLA_PRODUCT_VERSION=7.0REDHAT_SUPPORT_PRODUCT="Red Hat Enterprise Linux"REDHAT_SUPPORT_PRODUCT_VERSION=7.0

results in these information items:

Key Valuename “Red Hat Enterprise Linux Server”version “7.0 (Maipo)”id “rhel”id_like “fedora”version_id “7.0”pretty_name “Red Hat Enterprise Linux Server 7.0 (Maipo)”ansi_color “0;31”cpe_name “cpe:/o:redhat:enterprise_linux:7.0:GA:server”home_url “https://www.redhat.com/”bug_report_url “https://bugzilla.redhat.com/”redhat_bugzilla_product “Red Hat Enterprise Linux 7”redhat_bugzilla_product_version “7.0”redhat_support_product “Red Hat Enterprise Linux”redhat_support_product_version “7.0”codename “Maipo”

26 Chapter 9. Os-release file

Page 31: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

CHAPTER 10

Lsb_release command output

The lsb_release command is expected to be in the PATH, and is invoked as follows:

lsb_release -a

The command output is expected to be encoded in UTF-8.

Only lines in the command output with the following format will be used:

<attr-name>: <attr-value>

Where:

• <attr-name> is the name of the attribute, and

• <attr-value> is the attribute value.

The attribute names are stripped from surrounding blanks, any remaining blanks are translated to underscores, theyare translated to lower case, and then become the keys of the information items from the lsb_release command outputdata source.

The attribute values are stripped from surrounding blanks, and then become the values of the information items fromthe lsb_release command output data source.

See the lsb_release man page for a description of standard attributes returned by the lsb_release command.

Examples:

1. The following lsb_release command output:

No LSB modules are available.Distributor ID: UbuntuDescription: Ubuntu 14.04.3 LTSRelease: 14.04Codename: trusty

results in these information items:

27

Page 32: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

Key Valuedistributor_id “Ubuntu”description “Ubuntu 14.04.3 LTS”release “14.04”codename “trusty”

2. The following lsb_release command output:

LSB Version: n/aDistributor ID: SUSE LINUXDescription: SUSE Linux Enterprise Server 12 SP1Release: 12.1Codename: n/a

results in these information items:

Key Valuelsb_version “n/a”distributor_id “SUSE LINUX”description “SUSE Linux Enterprise Server 12 SP1”release “12.1”codename “n/a”

28 Chapter 10. Lsb_release command output

Page 33: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

CHAPTER 11

Distro release file

Unless specified with a particular path name when using the distro.LinuxDistribution class, the distrorelease file is found by using the first match in the alphabetically sorted list of the files matching the following pathname patterns:

• /etc/*-release

• /etc/*_release

• /etc/*-version

• /etc/*_version

where the following special path names are excluded:

• /etc/debian_version

• /etc/system-release

• /etc/os-release

and where the first line within the file has the expected format.

The algorithm to sort the files alphabetically is far from perfect, but the distro release file has the least priority as adata source, and it is expected that distributions provide one of the other data sources.

The distro release file is expected to be encoded in UTF-8.

Only its first line is used, and it is expected to have the following format:

<name> [[[release] <version_id>] (<codename>)]

Where:

• square brackets indicate optionality,

• <name> is the distro name,

• <version_id> is the distro version, and

• <codename> is the distro codename.

The following information items can be found in a distro release file (shown with their keys and data types):

29

Page 34: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

• id (string): Distro ID, taken from the first part of the file name before the hyphen (-) or underscore (_).

Note that the distro ID is not normalized or translated to lower case at this point; this happens only for the resultof the distro.id() function.

• name (string): Distro name, as found in the first line of the file.

• version_id (string): Distro version, as found in the first line of the file. If not found, this information itemwill not exist.

• codename (string): Distro codename, as found in the first line of the file. If not found, this information itemwill not exist.

Note that the string in the codename field is not always really a codename. For example, openSUSE returns“x86_64”.

Examples:

1. The following distro release file /etc/centos-release:

CentOS Linux release 7.1.1503 (Core)

results in these information items:

Key Valueid “centos”name “CentOS Linux”version_id “7.1.1503”codename “Core”

2. The following distro release file /etc/oracle-release:

Oracle Linux Server release 7.1

results in these information items:

Key Valueid “oracle”name “Oracle Linux Server”version_id “7.1”

3. The following distro release file /etc/SuSE-release:

openSUSE 42.1 (x86_64)

results in these information items:

Key Valueid “SuSE”name “openSUSE”version_id “42.1”codename “x86_64”

30 Chapter 11. Distro release file

Page 35: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Python Module Index

ddistro, 3

31

Page 36: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Linux Distribution - a Linux OS platform information API, Release 1.3.0

32 Python Module Index

Page 37: Linux Distribution - a Linux OS platform information API · “mageia” Mageia “mandriva” Mandriva Linux “parallels” Parallels “pidora” Pidora “raspbian” Raspbian

Index

Bbuild_number() (distro.LinuxDistribution method), 21build_number() (in module distro), 14

Ccodename() (distro.LinuxDistribution method), 21codename() (in module distro), 14

Ddistro (module), 3distro_release_attr() (distro.LinuxDistribution method),

21distro_release_attr() (in module distro), 18distro_release_info() (distro.LinuxDistribution method),

21distro_release_info() (in module distro), 17

Iid() (distro.LinuxDistribution method), 20id() (in module distro), 11info() (distro.LinuxDistribution method), 21info() (in module distro), 14

Llike() (distro.LinuxDistribution method), 21like() (in module distro), 14linux_distribution() (distro.LinuxDistribution method),

20linux_distribution() (in module distro), 11LinuxDistribution (class in distro), 19lsb_release_attr() (distro.LinuxDistribution method), 21lsb_release_attr() (in module distro), 17lsb_release_info() (distro.LinuxDistribution method), 21lsb_release_info() (in module distro), 17

Mmajor_version() (distro.LinuxDistribution method), 20major_version() (in module distro), 14minor_version() (distro.LinuxDistribution method), 20

minor_version() (in module distro), 14

Nname() (distro.LinuxDistribution method), 20name() (in module distro), 12NORMALIZED_DISTRO_ID (in module distro), 23NORMALIZED_LSB_ID (in module distro), 23NORMALIZED_OS_ID (in module distro), 23

Oos_release_attr() (distro.LinuxDistribution method), 21os_release_attr() (in module distro), 17os_release_info() (distro.LinuxDistribution method), 21os_release_info() (in module distro), 17

Uuname_attr() (distro.LinuxDistribution method), 21uname_info() (distro.LinuxDistribution method), 21

Vversion() (distro.LinuxDistribution method), 20version() (in module distro), 13version_parts() (distro.LinuxDistribution method), 20version_parts() (in module distro), 13

33