Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect macOS/OSX using platform package #233

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 8 additions & 18 deletions src/rospkg/os_detect.py
Original file line number Diff line number Diff line change
Expand Up @@ -298,10 +298,7 @@ def get_codename(self):


def _osx_codename(major, minor):
if major == 10:
key = '%s.%s' % (major, minor)
else:
key = '%s' % (major)
key = '%s.%s' % (major, minor) if major == '10' else '%s' % (major)
if key not in _osx_codename_map:
raise OsNotDetected("unrecognized version: %s" % key)
return _osx_codename_map[key]
Expand All @@ -311,26 +308,19 @@ class OSX(OsDetector):
"""
Detect OS X
"""
def __init__(self, sw_vers_file="/usr/bin/sw_vers"):
self._sw_vers_file = sw_vers_file

def is_os(self):
return os.path.exists(self._sw_vers_file)
return platform.version() == 'Darwin'

def get_codename(self):
def get_version(self):
if self.is_os():
version = self.get_version()
import distutils.version # To parse version numbers
try:
ver = distutils.version.StrictVersion(version).version
except ValueError:
raise OsNotDetected("invalid version string: %s" % (version))
return _osx_codename(*ver[0:2])
return platform.mac_ver()[0]
raise OsNotDetected('called in incorrect OS')

def get_version(self):
def get_codename(self):
if self.is_os():
return _read_stdout([self._sw_vers_file, '-productVersion'])
version = self.get_version()
major, minor = version.split('.')[:2]
return _osx_codename(major, minor)
raise OsNotDetected('called in incorrect OS')


Expand Down