From 0e17fe52cafe014f93bfdbf2e7d6b20d2c2eb747 Mon Sep 17 00:00:00 2001 From: Tully Foote Date: Wed, 9 Feb 2011 00:36:22 +0000 Subject: [PATCH] patch from #3239 --- core/roslib/src/roslib/os_detect.py | 40 ++++++++++++++++++- .../test_roslib/test/test_roslib_os_detect.py | 4 ++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/core/roslib/src/roslib/os_detect.py b/core/roslib/src/roslib/os_detect.py index cced1c88..084c66b0 100644 --- a/core/roslib/src/roslib/os_detect.py +++ b/core/roslib/src/roslib/os_detect.py @@ -188,6 +188,44 @@ class Mint(OSBase): return "mint" ###### END Mint SPECIALIZATION ######################## +###### OpenSuse SPECIALIZATION ######################### +class OpenSuse(OSBase): + """ + Detect OpenSuse OS. + """ + def check_presence(self): + try: + filename = "/etc/SuSE-brand" + if os.path.exists(filename): + with open(filename, 'r') as fh: + os_list = fh.read().split() + if len(os_list) > 0 and os_list[0] == "openSUSE": + return True + except: + pass + return False + + def get_version(self): + try: + filename = "/etc/SuSE-brand" + if os.path.exists(filename): + with open(filename, 'r') as fh: + os_list = fh.read().strip().split('\n') + if len(os_list) == 2: + os_list = os_list[1].split(' = ') + if os_list[0] == "VERSION": + return os_list[1] + except: + return False + + return False + + def get_name(self): + return "opensuse" + +###### END OpenSuse SPECIALIZATION ######################## + + ###### Fedora SPECIALIZATION ######################### class Fedora(OSBase): """ @@ -428,7 +466,7 @@ class FreeBSD(OSBase): class OSDetect: """ This class will iterate over registered classes to lookup the active OS and version""" - def __init__(self, os_list = [Debian(), Ubuntu(), Mint(), Macports(), Arch(), Fedora(), Rhel(), Gentoo(), Cygwin(), FreeBSD()]): + def __init__(self, os_list = [Debian(), Ubuntu(), Mint(), Macports(), Arch(), OpenSuse(), Fedora(), Rhel(), Gentoo(), Cygwin(), FreeBSD()]): self._os_list = os_list for o in self._os_list: if not isinstance(o, OSBase): diff --git a/test/test_roslib/test/test_roslib_os_detect.py b/test/test_roslib/test/test_roslib_os_detect.py index 2f069342..1cdfa34b 100644 --- a/test/test_roslib/test/test_roslib_os_detect.py +++ b/test/test_roslib/test/test_roslib_os_detect.py @@ -76,6 +76,10 @@ class RoslibOsDetectTest(unittest.TestCase): arch = roslib.os_detect.Arch() self.assertEqual("arch", arch.get_name()) + def test_tripwire_opensuse(self): + opensuse = roslib.os_detect.OpenSuse() + self.assertEqual("opensuse", opensuse.get_name()) + def test_tripwire_fedora(self): fedora = roslib.os_detect.Fedora() self.assertEqual("fedora", fedora.get_name())