From 45d6f17c4eda5a47bbc835e69aac73e11b692dbf Mon Sep 17 00:00:00 2001 From: Thomas Bechtold Date: Thu, 12 May 2016 15:41:50 +0200 Subject: [PATCH] Add support for openSUSE and SLES In the SLES case, the distro name from lsb_release is "SUSE LINUX" so the parsing needs to be adjusted to detect multi word strings as distro names. Both platforms use rpm as packaging system. Change-Id: I273d756a2ba24d0ce69990936fc0c241bfee7fa1 --- bindep/depends.py | 9 +++++++-- bindep/tests/test_depends.py | 26 ++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/bindep/depends.py b/bindep/depends.py index 067408c..9d90308 100644 --- a/bindep/depends.py +++ b/bindep/depends.py @@ -130,8 +130,13 @@ class Depends(object): return sorted(profiles) def platform_profiles(self): - distro, release, codename = subprocess.check_output( + lsbinfo = subprocess.check_output( ["lsb_release", "-cirs"], stderr=subprocess.STDOUT).lower().split() + # NOTE(toabctl): distro can be more than one string (i.e. "SUSE LINUX") + codename = lsbinfo[len(lsbinfo) - 1:len(lsbinfo)][0] + release = lsbinfo[len(lsbinfo) - 2:len(lsbinfo) - 1][0] + # NOTE(toabctl): space is a delimiter for bindep, so remove the spaces + distro = "".join(lsbinfo[0:len(lsbinfo) - 2]) atoms = set([distro]) atoms.add("%s-%s" % (distro, codename)) releasebits = release.split(".") @@ -140,7 +145,7 @@ class Depends(object): if distro in ["debian", "ubuntu"]: atoms.add("dpkg") self.platform = Dpkg() - elif distro in ["centos", "fedora"]: + elif distro in ["centos", "fedora", "opensuse", "suselinux"]: atoms.add("rpm") self.platform = Rpm() elif distro in ["gentoo"]: diff --git a/bindep/tests/test_depends.py b/bindep/tests/test_depends.py index 3e9f5f8..5476f6a 100644 --- a/bindep/tests/test_depends.py +++ b/bindep/tests/test_depends.py @@ -66,6 +66,18 @@ class TestDepends(TestCase): self.assertThat( depends.platform_profiles(), Contains("platform:fedora")) + def test_detects_opensuse(self): + self._mock_lsb("openSUSE") + depends = Depends("") + self.assertThat( + depends.platform_profiles(), Contains("platform:opensuse")) + + def test_detects_suse_linux(self): + self._mock_lsb("SUSE Linux") + depends = Depends("") + self.assertThat( + depends.platform_profiles(), Contains("platform:suselinux")) + def test_detects_ubuntu(self): self._mock_lsb("Ubuntu") depends = Depends("") @@ -104,6 +116,20 @@ class TestDepends(TestCase): depends.platform_profiles(), Contains("platform:rpm")) self.assertIsInstance(depends.platform, Rpm) + def test_opensuse_implies_rpm(self): + self._mock_lsb("openSUSE") + depends = Depends("") + self.assertThat( + depends.platform_profiles(), Contains("platform:rpm")) + self.assertIsInstance(depends.platform, Rpm) + + def test_suse_linux_implies_rpm(self): + self._mock_lsb("SUSE LINUX") + depends = Depends("") + self.assertThat( + depends.platform_profiles(), Contains("platform:rpm")) + self.assertIsInstance(depends.platform, Rpm) + def test_ubuntu_implies_dpkg(self): self._mock_lsb("Ubuntu") depends = Depends("")