Add Archlinux support
This commit adds archlinux support to bindep. It uses the pacman package manager's query interface to determine if the packages are installed. Change-Id: Idf69042b9072a2943f14ae9469cd42a252cc6b82
This commit is contained in:
parent
998519a543
commit
b232b230c3
@ -205,6 +205,9 @@ class Depends(object):
|
|||||||
elif distro in ["gentoo"]:
|
elif distro in ["gentoo"]:
|
||||||
atoms.add("emerge")
|
atoms.add("emerge")
|
||||||
self.platform = Emerge()
|
self.platform = Emerge()
|
||||||
|
elif distro in ["arch"]:
|
||||||
|
atoms.add("pacman")
|
||||||
|
self.platform = Pacman()
|
||||||
return ["platform:%s" % (atom,) for atom in sorted(atoms)]
|
return ["platform:%s" % (atom,) for atom in sorted(atoms)]
|
||||||
|
|
||||||
|
|
||||||
@ -294,6 +297,27 @@ class Emerge(Platform):
|
|||||||
return elements[0]
|
return elements[0]
|
||||||
|
|
||||||
|
|
||||||
|
class Pacman(Platform):
|
||||||
|
"""pacman specific implementation.
|
||||||
|
|
||||||
|
This shells out to pacman
|
||||||
|
"""
|
||||||
|
|
||||||
|
def get_pkg_version(self, pkg_name):
|
||||||
|
try:
|
||||||
|
output = subprocess.check_output(
|
||||||
|
['pacman', '-Q', pkg_name],
|
||||||
|
stderr=subprocess.STDOUT)
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
if e.returncode == 1 and e.output.endswith('was not found'):
|
||||||
|
return None
|
||||||
|
raise
|
||||||
|
# output looks like
|
||||||
|
# version
|
||||||
|
elements = output.strip().split(' ')
|
||||||
|
return elements[1]
|
||||||
|
|
||||||
|
|
||||||
def _eval_diff(operator, diff):
|
def _eval_diff(operator, diff):
|
||||||
"""Return the boolean result for operator given diff.
|
"""Return the boolean result for operator given diff.
|
||||||
|
|
||||||
|
@ -31,6 +31,7 @@ from bindep.depends import _eval
|
|||||||
from bindep.depends import Depends
|
from bindep.depends import Depends
|
||||||
from bindep.depends import Dpkg
|
from bindep.depends import Dpkg
|
||||||
from bindep.depends import Emerge
|
from bindep.depends import Emerge
|
||||||
|
from bindep.depends import Pacman
|
||||||
from bindep.depends import Rpm
|
from bindep.depends import Rpm
|
||||||
|
|
||||||
|
|
||||||
@ -145,6 +146,13 @@ class TestDepends(TestCase):
|
|||||||
depends.platform_profiles(), Contains("platform:dpkg"))
|
depends.platform_profiles(), Contains("platform:dpkg"))
|
||||||
self.assertIsInstance(depends.platform, Dpkg)
|
self.assertIsInstance(depends.platform, Dpkg)
|
||||||
|
|
||||||
|
def test_arch_implies_pacman(self):
|
||||||
|
with self._mock_lsb("Arch"):
|
||||||
|
depends = Depends("")
|
||||||
|
self.assertThat(
|
||||||
|
depends.platform_profiles(), Contains("platform:pacman"))
|
||||||
|
self.assertIsInstance(depends.platform, Pacman)
|
||||||
|
|
||||||
def test_finds_profiles(self):
|
def test_finds_profiles(self):
|
||||||
depends = Depends(dedent("""\
|
depends = Depends(dedent("""\
|
||||||
foo
|
foo
|
||||||
@ -411,6 +419,36 @@ class TestEmerge(TestCase):
|
|||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
|
|
||||||
|
class TestPacman(TestCase):
|
||||||
|
|
||||||
|
def test_unknown_package(self):
|
||||||
|
platform = Pacman()
|
||||||
|
|
||||||
|
def _side_effect_raise(*args, **kwargs):
|
||||||
|
raise subprocess.CalledProcessError(
|
||||||
|
1, [], "error: package 'foo' was not found")
|
||||||
|
|
||||||
|
mock_checkoutput = self.useFixture(
|
||||||
|
fixtures.MockPatchObject(subprocess, "check_output")).mock
|
||||||
|
mock_checkoutput.side_effect = _side_effect_raise
|
||||||
|
|
||||||
|
self.assertEqual(None, platform.get_pkg_version("foo"))
|
||||||
|
mock_checkoutput.assert_called_once_with(
|
||||||
|
['pacman', '-Q', 'foo'],
|
||||||
|
stderr=subprocess.STDOUT)
|
||||||
|
self.assertEqual(None, platform.get_pkg_version("foo"))
|
||||||
|
|
||||||
|
def test_installed_version(self):
|
||||||
|
platform = Pacman()
|
||||||
|
mock_checkoutput = self.useFixture(
|
||||||
|
fixtures.MockPatchObject(subprocess, "check_output")).mock
|
||||||
|
mock_checkoutput.return_value = 'foo 4.0.0-2'
|
||||||
|
self.assertEqual("4.0.0-2", platform.get_pkg_version("foo"))
|
||||||
|
mock_checkoutput.assert_called_once_with(
|
||||||
|
['pacman', '-Q', 'foo'],
|
||||||
|
stderr=subprocess.STDOUT)
|
||||||
|
|
||||||
|
|
||||||
class TestRpm(TestCase):
|
class TestRpm(TestCase):
|
||||||
|
|
||||||
# NOTE: test_not_installed is not implemented as rpm seems to only be aware
|
# NOTE: test_not_installed is not implemented as rpm seems to only be aware
|
||||||
|
Loading…
x
Reference in New Issue
Block a user