8.2. platformids.platforms¶
The platforms module provides the identifiers for the runtime platform as defined by the OS and distribution. The values are either scanned from the current platform by:
1 2 3 4 5 from platformids.platforms import PlatformParameters x = PlatformParameters() # creates an empty object x.scan() # scans the platform print(str(x)) # prints display-format, see also 'repr'
For predefined and tested platforms on amd64 and arm64/32 refer to the table of standard OS.
For example:
Fedora27:
category = posix - RTE_POSIX ostype = linux - RTE_LINUX dist = fedora - RTE_FEDORA distrel = fedora27 - RTE_FEDORA27 dist-rel-name = Twenty Seven dist-vers = [27, 0, 0] os-vers = [4, 16, 15] hexversion = os-hexversion = 0
OS-X-10.6.8 - SnowLeopard:
category = posix - RTE_POSIX ostype = darwin - RTE_DARWIN dist = osx - RTE_OSX distrel = osx-10.6.8 - RTE_OSX1068 dist-rel-name = todo-distrelname dist-vers = [10, 6, 8] os-vers = [10, 8, 0] hexversion = os-hexversion = 0
CentOS7 - aarch64:
category = posix - RTE_POSIX ostype = linux - RTE_LINUX dist = centos - RTE_CENTOS distrel = centos-7.5.1804 - RTE_CENTOS75 dist-rel-name = Core dist-vers = [7, 5, 1804] os-vers = [4, 14, 52] hexversion = os-hexversion = 0
Armbian - armhfx:
Or in case of Armbian derived from debian the release names are coupled, while the release numbering is independent:
category = posix - RTE_POSIX ostype = linux - RTE_LINUX dist = armbian - RTE_ARMBIAN distrel = armbian-5.50.0 - RTE_ARMBIAN5500 dist-rel-name = Armbian-stretch dist-vers = [5, 50, 0] os-vers = [4, 14, 52] hexversion = os-hexversion = 0
Windows7 Ultimate:
The windows release provides the additional windows specific parameters ServicePack, ProductType, and SuiteMask.
category = windows - RTE_WINDOWS ostype = nt - RTE_NT dist = winws distrel = nt-6.1.7601 dist-rel-name = Windows7U dist-vers = [6, 1, 7601] os-vers = [7, 0, 0] hexversion = RTE_FEDORA27 os-hexversion = 0 wServicePack = [1, 0] # see [GetVersionEx] wProductType = 1 # see [GetVersionEx] wSuiteMask = 256 # see [GetVersionEx]
8.2.1. Module¶
The doc-strings of the document are spared in order to support in any case a slim memory-print and fast load time.
The module ‘platforms’ provides the class for the representation of platform parameters. This includes the scan of the current platform and the calculation of arbitrary hexadecimal labels for the fast processing of repetitive comparisons.
The supported implementations are: CPython, IPython, IronPython, Jython, and PyPy.
8.2.2. PlatformParameters¶
The class provides the representation of the current and/or a user provided platform. The automatic scan of the current runtime environment has to be triggered explicitly by the method platformids.PlatformParameters.scan(). The call replaces all attribute values of the current instance by the detected values.
8.2.2.1. Attributes¶
The following public attributes are provided for the hierachical platform categorization:
category
The type of operating system.
category := <class-of-os> class-of-os := ( wpemu # RTE_WPEMU | posix # RTE_POSIX | pwemu # RTE_PWEMU | windows # RTE_WIN )
ostype
The family of operating systems.
ostype := <type-of-os> type-of-os := ( bsd # RTE_BSD | cygwinnt # RTE_CYGWINNT | darwin # RTE_DARWIN | linux # RTE_LINUX | nt # RTE_NT | unix # RTE_UNIX )
dist
The packaged distributions of operating systems.
dist := <name-of-distribution> name-of-distribution := ( centos # RTE_CENTOS | debian # RTE_DEBIAN | fedora # RTE_FEDORA | nt63 # RTE_NT63 | nt100 # RTE_NT100 | openbsd # RTE_OPENBSD | osx # RTE_OSX | rhel # RTE_RHEL | suse # RTE_SUSE # and others )
distrel
A specific release of a packaged operating system.
distrel := ( centos76 # CentOS-7.6 or CentOS-7.6-1804 | debian96 # Debian-9.6 | fedora27 # Fedora27 | openbsd63 # OpenBSD-6.3 | rhel76 # RHEL-7.6 | rhel8 # RHEL-8 / 8.0 | snowleopard # OS-X-10.6.8 / OS-X-10.6.0 | windows10p # Windows 10 Professional | windows2012r2 # Windows Server 2010R2 | windows2016s # Windows Server 2016 | windows2019se # Windows Server 2019 Essentials | windows7u # Windows 7 Ultimate # and others )
distrel_hexversion
The numeric bitmask of the release version representing all previous attributes within one 32-bit integer. See bitmasks:
distrel := ( RTE_RHEL73 # RHEL 7.3 | RTE_RHEL8 # RHEL 8.0 | RTE_FEDORA27 # Fedora27 | RTE_DEBIAN96 # Debian-9.6 | RTE_W10P # Windows 10 Professional | RTE_W2016 # Windows Server 2016 | RTE_OSX1068 # OS-X Snowleopard # and others )
distrel_version
3-valued integer version of the distribution
ostype_version
3-valued integer version of the OS kernel
8.2.2.2. __init__¶
-
PlatformParameters.
__init__
(*args, **kargs)[source]¶ Creates an empty object. No automatic call of PlatformParameters.scan(). The instance could be either initialized by the provided parameters, or remains empty - which is zero 0.
Each call of PlatformParameters.scan() replaces the previous values.
- Parameters
args –
- Optional positional parameters in the following order.
The corresponding keyword-arguments dominate.
args[0] := category args[1] := ostype args[2] := dist args[3] := distrel
kargs –
- category:
The category for initialization.
default := 0
- ostype:
The ostype for initialization.
default := 0
- dist:
The dist for initialization.
default := 0
- distrel:
The distrel for initialization.
default := 0
- Returns:
Initial instance, optionally initialized by the provided parameters.
- Raises:
pass-through
8.2.2.3. __and__¶
-
PlatformParameters.
__and__
(other)[source]¶ The & operator for the resulting hexversion:
self-bitmask & other-bitmask
- Parameters
other –
The bitmask for operations.
other := ( <int-32bit-mask> # compare with hexversion | <dictionary>) # compare keys only | <tuple>) # compare key-index only | <instance-of-PlatformParameters> # compare both hexversions )
- Returns
The resulting bitmask as numeric value.
- Raises
pass-through –
8.2.2.4. __eq__¶
-
PlatformParameters.
__eq__
(other)[source]¶ Supports standard comparison with the types PlatformParameters, and dict. In case of a dict the attributes are used as keys literally.
- Parameters
other –
The instannce to be compared. The comparison is provided as:
literal contents of objects:
literally for objects PlatformParameters, or partially for dict.
partial hierarchical matches
The partial comparison is based on the keys provided by the dictionary argument. Only attributes with a corresponding key are compared.
The following items are handled specially:
- distrel_version, ostype_version:
The present values are compared only, e.g. the following is considered as True
self.distrel_version = [1, 2, 3] other.distrel_version = [1, 2,] TRUE: self.distrel_version == other.distrel_version
While still:
self.distrel_version = [1, 2, 3] other.distrel_version = [1, 2, 7] FALSE: self.distrel_version == other.distrel_version
- distrel:
Valuesa are compared by startswith() e.g. the following is considered as True
self.distrel = 'fedora-27.0.0' other.distrel = 'fedora-27.0' TRUE: self.distrel == other.distrel
While still:
self.distrel = 'fedora-27.0.0' other.distrel = 'fedora-27.0.1' FALSE: self.distrel == other.distrel
integer bit masks
Special treatment of integers is provided:
category:
When a valid category, self.category is compared only.
ostype:
When a valid ostype, self.ostype is compared only.
dist and/or distrel:
The value is compared to the same maximal extend.
- Returns
relevant parts are equal - see args. False: else
- Return type
True
- Raises
KeyError –
AttributeError –
8.2.2.6. __iand__¶
-
PlatformParameters.
__iand__
(other)[source]¶ The in-place & operator for the resulting hexversion:
self-bitmask &= other-bitmask
- Parameters
other –
The bitmask for operations.
other := (<int-32bit-mask> | <instance-of-PlatformParameters>)
- Returns
The resulting bitmask as numeric value.
- Raises
pass-through –
8.2.2.7. __int__¶
8.2.2.8. __ior__¶
-
PlatformParameters.
__ior__
(other)[source]¶ The in-place | operator for the resulting hexversion:
self-bitmask |= other-bitmask
- Parameters
other –
The bitmask for operations.
other := (<int-32bit-mask> | <instance-of-PlatformParameters>)
- Returns
The resulting bitmask as numeric value.
- Raises
pass-through –
8.2.2.10. __len__¶
8.2.2.12. __or__¶
8.2.2.13. __rand__¶
-
PlatformParameters.
__rand__
(other)[source]¶ The r-side & operator for the resulting hexversion:
other-bitmask & self-bitmask
- Parameters
other –
The bitmask for operations.
other := (<int-32bit-mask> | <instance-of-PlatformParameters>)
- Returns
The resulting bitmask as numeric value.
- Raises
pass-through –
8.2.2.15. __ror__¶
-
PlatformParameters.
__ror__
(other)[source]¶ The right-side | operator for the resulting hexversion:
other-bitmask | self-bitmask
- Parameters
other –
The bitmask for operations.
other := (<int-32bit-mask> | <instance-of-PlatformParameters>)
- Returns
The resulting bitmask as numeric value.
- Raises
pass-through –
8.2.2.18. get_hexversion¶
8.2.2.19. get_oshexversion¶
8.2.2.20. get_json¶
8.2.2.21. items¶
8.2.2.23. pretty_format¶
-
PlatformParameters.
pretty_format
(raw=False, **kargs)[source]¶ Formats and returns a string of attributes.
- Parameters
raw –
Controls the use of the value types:
raw := ( True # prints the internal types | False # prints the symbolic names where applicable ) default := False
kargs –
- quiet:
Supress standard display contents.
default := False
- terse:
Format for postprocessing.
default := False
- type:
Defines the type for the output:
type := ( bashvars | json | raw | repr | str )
default := str
- Returns
Formatted string of attributes.
- Raises
TypeError –
pass-through –
8.2.2.24. scan¶
-
PlatformParameters.
scan
()[source]¶ Scans local platform for attributes specifying the underlying OS platform including the distribution. The provided data is consistent across all supported Python implementations including Jython. Internally calls platformids.platformids.fetch_platform_distribution().
dist
distrel
distrel_hexversion
distrel_id
distrel_version
ostype
ostype_id
ostype_version
Sets the member attributes:
- distrel_version:
Three-value segments of ditribution version as numeric tuple.
distrel_version := (<#major>, <#minor>, <#micro>)
- distrel_id
String identifier of the complete distribution. This varies in dependency of the distribution. The state reflects commonly the distribution release, and when available the update/upgrade releases. Which varies and is for some rolling distributions currently not available.
For example:
'Ubuntu1904' - Ubuntu-19.04 'arch20190401' - ArchLinux-2019.04.01 'armbian550' - Armbian-5.50 'centos76' - CentOS-7.6.1810 'cygwin268' - Cygwin-2.6.8 'fedora29' - Fedora29 'kali20191' - KaliLinux-2019.1 'nt1001809' - NT-10.0.1809 'osx1068' - OSX-10.6.8
- dist:
String identifier of the distributions ‘dist’ value.
- distrel:
The human readable distribution release:
distrel := <dist>-<major>.<minor>.<micro>
- ostype:
The string identifier of the ‘ostype’. For example:
'nt', 'linux', ...
- ostype_id:
Same as ‘ostype’.
- ostype_version:
The numeric tuple of the os release:
ostype_version := (<#major>, <#minor>, <#micro>)
- distrel_hexversion
The calculated hexadcimal identifier ot the distribution.