feat: add apt.is_installed()
function
This commit is contained in:
parent
12daf6a1e3
commit
4dede6072c
|
@ -51,6 +51,19 @@ def install(c, *packages, **kwargs):
|
||||||
return c.run(f'DEBIAN_FRONTEND={frontend} apt-get --assume-yes install {packages}')
|
return c.run(f'DEBIAN_FRONTEND={frontend} apt-get --assume-yes install {packages}')
|
||||||
|
|
||||||
|
|
||||||
|
def is_installed(c, package):
|
||||||
|
"""
|
||||||
|
Check if the given APT package is installed.
|
||||||
|
|
||||||
|
:param c: Fabric connection.
|
||||||
|
|
||||||
|
:param package: Name of package to be checked.
|
||||||
|
|
||||||
|
:returns: ``True`` if package is installed, else ``False``.
|
||||||
|
"""
|
||||||
|
return c.run(f'dpkg-query -s {package}', warn=True).ok
|
||||||
|
|
||||||
|
|
||||||
def update(c):
|
def update(c):
|
||||||
"""
|
"""
|
||||||
Update the APT package lists. Essentially this runs:
|
Update the APT package lists. Essentially this runs:
|
||||||
|
|
|
@ -25,6 +25,21 @@ class TestInstall(TestCase):
|
||||||
c.run.assert_called_once_with('DEBIAN_FRONTEND=noninteractive apt-get --assume-yes install postfix')
|
c.run.assert_called_once_with('DEBIAN_FRONTEND=noninteractive apt-get --assume-yes install postfix')
|
||||||
|
|
||||||
|
|
||||||
|
class TestIsInstalled(TestCase):
|
||||||
|
|
||||||
|
def test_already_installed(self):
|
||||||
|
c = MagicMock()
|
||||||
|
c.run.return_value.ok = True
|
||||||
|
self.assertTrue(mod.is_installed(c, 'postfix'))
|
||||||
|
c.run.assert_called_once_with('dpkg-query -s postfix', warn=True)
|
||||||
|
|
||||||
|
def test_not_installed(self):
|
||||||
|
c = MagicMock()
|
||||||
|
c.run.return_value.ok = False
|
||||||
|
self.assertFalse(mod.is_installed(c, 'postfix'))
|
||||||
|
c.run.assert_called_once_with('dpkg-query -s postfix', warn=True)
|
||||||
|
|
||||||
|
|
||||||
class TestUpdate(TestCase):
|
class TestUpdate(TestCase):
|
||||||
|
|
||||||
def test_basic(self):
|
def test_basic(self):
|
||||||
|
|
Loading…
Reference in a new issue