OS detection

OS detection is a critical capability of many ROS tools in the ROS build toolchain. The rospkg.os_detect module provides and extendable library for detecting various operating systems. It is focused on detecting operating systems used with ROS.

Currently supported OSes:

  • Arch Linux
  • Cygwin
  • Debian
  • Fedora
  • FreeBSD
  • Gentoo
  • Mint
  • OS X
  • Red Hat Linux
  • Ubuntu
class rospkg.os_detect.OsNotDetected[source]

Exception to indicate failure to detect operating system.

class rospkg.os_detect.OsDetect(os_list)[source]

Detects the current operating system. This class will iterate over registered classes to lookup the active OS and version. The list of detectors can be overridden in the constructor; otherwise it will default to OsDetector classes provided by this library.

default_os_list

List of currently registered detectors. Must not be modified directly.

static register_default(os_name, os_detector)[source]

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.

detect_os() → tuple[source]
Returns:(os_name, os_version, os_codename), (str, str, str)
Raises :OsNotDetected if OS could not be detected
get_detector([name]) → OsDetector[source]

Get detector used for specified OS name, or the detector for this OS if name is None.

Raises :KeyError
add_detector(name, detector)[source]

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
  • detectorOsDetector instance
get_os() → OsDetector

Get OsDetector for this operating system.

Raises :OsNotDetected if OS could not be detected
get_name() → str[source]
Returns:Name of current operating system. See OS_* definitions in this module for possible values.
Raises :OsNotDetected if OS could not be detected
get_version() → str[source]
Returns:Version of current operating system
Raises :OsNotDetected if OS could not be detected
get_codename() → str[source]
Returns:Codename of current operating system if available, or empty string if OS does not provide codename.
Raises :OsNotDetected if OS could not be detected
class rospkg.os_detect.OsDetector[source]

Generic API for detecting a specific OS.

get_codename()[source]
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()[source]
Returns:standardized version for this OS. (ala Ubuntu Hardy Heron = “8.04”)
Raises :OsNotDetected if called on incorrect OS.
is_os()[source]
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.

OS name definitions

rospkg.os_detect.OS_ARCH

Name used for Arch Linux OS.

rospkg.os_detect.OS_CYGWIN

Name used for Cygwin OS.

rospkg.os_detect.OS_DEBIAN

Name used for Debian OS.

rospkg.os_detect.OS_FREEBSD

Name used for FreeBSD OS.

rospkg.os_detect.OS_GENTOO

Name used for Gentoo.

rospkg.os_detect.OS_MINT

Name used for Mint OS.

rospkg.os_detect.OS_OPENSUSE

Name used for OpenSUSE OS.

rospkg.os_detect.OS_OSX

Name used for OS X.

rospkg.os_detect.OS_RHEL

Name used for Red Hat Enterprise Linux.

rospkg.os_detect.OS_UBUNTU

Name used for Ubuntu OS.

Linux helper methods

rospkg.os_detect.lsb_get_os() → str[source]

Linux: wrapper around lsb_release to get the current OS

rospkg.os_detect.lsb_get_codename() → str[source]

Linux: wrapper around lsb_release to get the current OS codename

rospkg.os_detect.lsb_get_version() → str[source]

Linux: wrapper around lsb_release to get the current OS version

rospkg.os_detect.uname_get_machine() → str[source]

Linux: wrapper around uname to determine if OS is 64-bit

Project Versions

Table Of Contents

Previous topic

ROS environment variable access

Next topic

rospkg.distro Python library

This Page