xylem.os_support package¶
Submodules¶
xylem.os_support.impl module¶
- class xylem.os_support.impl.OS¶
Bases: builtins.object
Abstract OS plugin base class.
OS plugins should define entry points as classes derived from this.
Operating systems are described by a list of increasingly specific names, where the most specific of those is referred to as the name of the operating system. The description furthermore includes a operating system version, which can be a version number string or code name.
Operating systems can name their default installer and furthermore list additional applicable installer names, each with a number as priority (higher number take precedence).
- get_default_installer_name()¶
Get name of default installer as described by OS plugin.
Return type: str
- get_installer_priority(installer_name)¶
Get priority of installer as described by OS plugin.
Parameters: installer_name (str) – name of installer in question Returns: priority of this installer if the os defines it, else None Return type: number or None
- get_name()¶
Get the most specific name of the described operating system.
Return type: string
- get_names()¶
Get a list of names describing this operating system.
Returns: list of increasingly specific os names Return type: list of strings
- get_tuple()¶
Get (name,version) tuple.
Return type: (str,str)
- get_version()¶
Get version of this operating system.
Return type: string
- is_os()¶
Return true if the current OS matches the one this object describes.
Return type: bool
- class xylem.os_support.impl.OSSupport¶
Bases: builtins.object
OSSupport manages the OS plugins and options such as override_os.
Can detect the current OS from the installed OS plugins or use the override option. Moreover manages options such as disabling specific plugins.
In order to set up, either call detect_os() or override_os() and subsequently access it with current_os()
- detect_os()¶
Detects and sets the current OS.
The first OS plugin that returns True for OS.is_os() is the detected one. If multiple os plugins would accept the current OS, a warning is printed to the user.
Raises UnsupportedOSError: If no OS plugin accepts the current OS
- get_current_os()¶
Return OS object of current OS.
Detect current OS if not yet detected or overridden.
Return type: OS Raises UnsupportedOSError: If OS is not set and cannot be detected.
- get_default_installer_names()¶
Return mapping of os name to default installer for all os.
- get_os_plugin(name)¶
Return os plugin object for given os name or None if not known.
- get_os_plugin_names()¶
Return list of known/configured os names.
- get_os_plugins()¶
Return list of is plugin objects.
- override_os(os_tuple)¶
Override to to (name,version) tuple.
A plugin with name must be installed.
Raises UnsupportedOSError: if specified os name is not known
- class xylem.os_support.impl.OverrideOS(os, version)¶
Bases: xylem.os_support.impl.OS
Special OS class that acts as a proxy to another OS with fixed version.
OverrideOS takes another OS object and delegates all queries to that, except for detection and version, which are fixed by the OverrideOS.
- get_default_installer_name()¶
Return the delegate’s default installer.
- get_installer_priority(installer_name)¶
Return the delegate’s installer priority.
- get_name()¶
Return the delegate’s name.
- get_names()¶
Return the delegate’s names.
- get_version()¶
Return the saved version from setup.
- exception xylem.os_support.impl.UnsupportedOSError¶
Bases: builtins.Exception
Operating system unsupported.
Detected operating system is not supported or could not be identified.
- xylem.os_support.impl.get_os_plugin_list()¶
Return list of OS plugin objects unique by name.
Load the os plugin classes from entry points, instantiating objects and ignoring duplicates (by os.name(), not entry point name).
Returns: list of the loaded plugin objects Raises InvalidPluginError: if one of the loaded plugins is invalid
- xylem.os_support.impl.load_os_plugin(entry_point)¶
Load OS plugin from entry point.
Parameters: entry_point – entry point object from pkg_resources Raises InvalidPluginError: if the plugin is not valid
xylem.os_support.os_detect module¶
Library for detecting the current OS, including detecting specific Linux distributions.
- class xylem.os_support.os_detect.Arch(release_file='/etc/arch-release')¶
Bases: xylem.os_support.os_detect.OsDetector
Detect Arch Linux.
- get_codename()¶
- get_version()¶
- is_os()¶
- class xylem.os_support.os_detect.Cygwin¶
Bases: xylem.os_support.os_detect.OsDetector
Detect Cygwin presence on Windows OS.
- get_codename()¶
- get_version()¶
- is_os()¶
- class xylem.os_support.os_detect.Fedora(release_file='/etc/redhat-release', issue_file='/etc/issue')¶
Bases: xylem.os_support.os_detect.OsDetector
Detect Fedora OS.
- get_codename()¶
- get_version()¶
- is_os()¶
- class xylem.os_support.os_detect.FreeBSD(uname_file='/usr/bin/uname')¶
Bases: xylem.os_support.os_detect.OsDetector
Detect FreeBSD OS.
- get_codename()¶
- get_version()¶
- is_os()¶
- class xylem.os_support.os_detect.Gentoo(release_file='/etc/gentoo-release')¶
Bases: xylem.os_support.os_detect.OsDetector
Detect Gentoo OS.
- get_codename()¶
- get_version()¶
- is_os()¶
- class xylem.os_support.os_detect.LsbDetect(lsb_name, get_version_fn=None)¶
Bases: xylem.os_support.os_detect.OsDetector
Generic detector for Debian, Ubuntu, and Mint
- get_codename()¶
- get_version()¶
- is_os()¶
- class xylem.os_support.os_detect.OSX(sw_vers_file='/usr/bin/sw_vers')¶
Bases: xylem.os_support.os_detect.OsDetector
Detect OS X
- get_codename()¶
- get_version()¶
- is_os()¶
- class xylem.os_support.os_detect.OpenSuse(brand_file='/etc/SuSE-brand', release_file='/etc/SuSE-release')¶
Bases: xylem.os_support.os_detect.OsDetector
Detect OpenSuse OS.
- get_codename()¶
- get_version()¶
- is_os()¶
- class xylem.os_support.os_detect.OsDetect(os_list=None)¶
Bases: builtins.object
This class will iterate over registered classes to lookup the active OS and version
- add_detector(name, detector)¶
Add detector to list of detectors used by this instance. detector will override any previous detectors associated with name.
Parameters: - name – OS name that detector matches
- detector – OsDetector instance
- default_os_list = [('windows', <xylem.os_support.os_detect.Windows object at 0x7f779e37d748>), ('ubuntu', <xylem.os_support.os_detect.LsbDetect object at 0x7f779e37d828>), ('rhel', <xylem.os_support.os_detect.Rhel object at 0x7f779e319da0>), ('qnx', <xylem.os_support.os_detect.QNX object at 0x7f779e319d68>), ('osx', <xylem.os_support.os_detect.OSX object at 0x7f779e319d30>), ('opensuse', <xylem.os_support.os_detect.OpenSuse object at 0x7f779e319cf8>), ('mint', <xylem.os_support.os_detect.LsbDetect object at 0x7f779e319f28>), ('gentoo', <xylem.os_support.os_detect.Gentoo object at 0x7f779e319ef0>), ('freebsd', <xylem.os_support.os_detect.FreeBSD object at 0x7f779e319eb8>), ('fedora', <xylem.os_support.os_detect.Fedora object at 0x7f779e319e80>), ('debian', <xylem.os_support.os_detect.LsbDetect object at 0x7f779e319fd0>), ('cygwin', <xylem.os_support.os_detect.Cygwin object at 0x7f779e319cc0>), ('arch', <xylem.os_support.os_detect.Arch object at 0x7f779e3195c0>)]¶
- detect_os(env=None)¶
Detect operating system. Return value can be overridden by the :env:`ROS_OS_OVERRIDE` environment variable.
Parameters: env – override os.environ Returns: (os_name, os_version, os_codename), (str, str, str) Raises: OsNotDetected if OS could not be detected
- get_codename()¶
- get_detector(name=None)¶
Get detector used for specified OS name, or the detector for this OS if name is None.
Raises: KeyError
- get_name()¶
- get_version()¶
- static register_default(os_name, os_detector)¶
Register detector to be used with all future instances of OsDetect. The new detector will have precedence over any previously registered detectors associated with os_name.
Parameters: - os_name – OS key associated with OS detector
- os_detector – OsDetector instance
- class xylem.os_support.os_detect.OsDetector¶
Bases: builtins.object
Generic API for detecting a specific OS.
- get_codename()¶
Returns: codename for this OS. (ala Ubuntu Hardy Heron = “hardy”). If codenames are not available for this OS, return empty string. Raises: OsNotDetected if called on incorrect OS.
- get_version()¶
Returns: standardized version for this OS. (ala Ubuntu Hardy Heron = “8.04”) Raises: OsNotDetected if called on incorrect OS.
- is_os()¶
Returns: if the specific OS which this class is designed to detect is present. Only one version of this class should return for any version.
- exception xylem.os_support.os_detect.OsNotDetected¶
Bases: builtins.Exception
Exception to indicate failure to detect operating system.
- class xylem.os_support.os_detect.QNX(uname_file='/bin/uname')¶
Bases: xylem.os_support.os_detect.OsDetector
Detect QNX realtime OS. @author: Isaac Saito
- get_codename()¶
- get_version()¶
- is_os()¶
- class xylem.os_support.os_detect.Rhel(release_file='/etc/redhat-release')¶
Bases: xylem.os_support.os_detect.Fedora
Detect Redhat OS.
- get_codename()¶
- get_version()¶
- is_os()¶
- class xylem.os_support.os_detect.Windows¶
Bases: xylem.os_support.os_detect.OsDetector
Detect Windows OS.
- get_codename()¶
- get_version()¶
- is_os()¶
- xylem.os_support.os_detect.read_issue(filename='/etc/issue')¶
Returns: list of strings in issue file, or None if issue file cannot be read/split
- xylem.os_support.os_detect.uname_get_machine()¶
Linux: wrapper around uname to determine if OS is 64-bit
xylem.os_support.plugins module¶
- class xylem.os_support.plugins.Debian¶
- class xylem.os_support.plugins.OSBase¶
Bases: xylem.os_support.impl.OS
OS plugin base class for builtin plugins.
This is an internal base class used for the plugins shipped with xylem, which use the os_detect module. In general, external plugins would want to derive from OS directly.
Derived classes should fill in the following member variables:
Variables: - names (list(str)) – list of names
- detect – Detector object supporting is_os(), get_version() and get_codename()
- use_codename (bool) – boolean to decide if numbered version or codename should be used
- installer_priorities (dict) – dict of installer_name => priority
- default_installer_name (str) – name of the desired default installer
- get_default_installer_name()¶
- get_installer_priority(installer_name)¶
- get_name()¶
- get_names()¶
- get_version()¶
- is_os()¶
- class xylem.os_support.plugins.OSX¶
- class xylem.os_support.plugins.Ubuntu¶
Module contents¶
Module to manage OS plugins and their use for OS detection.
- class xylem.os_support.OS¶
Bases: builtins.object
Abstract OS plugin base class.
OS plugins should define entry points as classes derived from this.
Operating systems are described by a list of increasingly specific names, where the most specific of those is referred to as the name of the operating system. The description furthermore includes a operating system version, which can be a version number string or code name.
Operating systems can name their default installer and furthermore list additional applicable installer names, each with a number as priority (higher number take precedence).
- get_default_installer_name()¶
Get name of default installer as described by OS plugin.
Return type: str
- get_installer_priority(installer_name)¶
Get priority of installer as described by OS plugin.
Parameters: installer_name (str) – name of installer in question Returns: priority of this installer if the os defines it, else None Return type: number or None
- get_name()¶
Get the most specific name of the described operating system.
Return type: string
- get_names()¶
Get a list of names describing this operating system.
Returns: list of increasingly specific os names Return type: list of strings
- get_tuple()¶
Get (name,version) tuple.
Return type: (str,str)
- get_version()¶
Get version of this operating system.
Return type: string
- is_os()¶
Return true if the current OS matches the one this object describes.
Return type: bool
- class xylem.os_support.OSSupport¶
Bases: builtins.object
OSSupport manages the OS plugins and options such as override_os.
Can detect the current OS from the installed OS plugins or use the override option. Moreover manages options such as disabling specific plugins.
In order to set up, either call detect_os() or override_os() and subsequently access it with current_os()
- detect_os()¶
Detects and sets the current OS.
The first OS plugin that returns True for OS.is_os() is the detected one. If multiple os plugins would accept the current OS, a warning is printed to the user.
Raises UnsupportedOSError: If no OS plugin accepts the current OS
- get_current_os()¶
Return OS object of current OS.
Detect current OS if not yet detected or overridden.
Return type: OS Raises UnsupportedOSError: If OS is not set and cannot be detected.
- get_default_installer_names()¶
Return mapping of os name to default installer for all os.
- get_os_plugin(name)¶
Return os plugin object for given os name or None if not known.
- get_os_plugin_names()¶
Return list of known/configured os names.
- get_os_plugins()¶
Return list of is plugin objects.
- override_os(os_tuple)¶
Override to to (name,version) tuple.
A plugin with name must be installed.
Raises UnsupportedOSError: if specified os name is not known
- exception xylem.os_support.UnsupportedOSError¶
Bases: builtins.Exception
Operating system unsupported.
Detected operating system is not supported or could not be identified.