checks: Stop looking for imports
We can't reliably tell user what system packages are missing as the name might be different on different systems. Addiotionally there's no reason why not rely on the packaging to be correct. Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
parent
804a0049f6
commit
23ca2fe5d2
@ -107,30 +107,11 @@ tools = [
|
|||||||
("cvs", "/usr/bin/cvs", None),
|
("cvs", "/usr/bin/cvs", None),
|
||||||
]
|
]
|
||||||
|
|
||||||
imports = [
|
|
||||||
("kobo", "kobo"),
|
|
||||||
("kobo-rpmlib", "kobo.rpmlib"),
|
|
||||||
("python-lxml", "lxml"),
|
|
||||||
("koji", "koji"),
|
|
||||||
("python-productmd", "productmd"),
|
|
||||||
("python-kickstart", "pykickstart.parser"),
|
|
||||||
("libselinux-python", "selinux"),
|
|
||||||
]
|
|
||||||
|
|
||||||
|
|
||||||
def check(conf):
|
def check(conf):
|
||||||
"""Check runtime environment and report errors about missing dependencies."""
|
"""Check runtime environment and report errors about missing dependencies."""
|
||||||
fail = False
|
fail = False
|
||||||
|
|
||||||
# Check python modules
|
|
||||||
for package, module in imports:
|
|
||||||
try:
|
|
||||||
__import__(module)
|
|
||||||
except ImportError:
|
|
||||||
print("Module '%s' doesn't exist. Install package '%s'." % (module, package))
|
|
||||||
fail = True
|
|
||||||
|
|
||||||
# Check tools
|
|
||||||
for package, path, test_if_required in tools:
|
for package, path, test_if_required in tools:
|
||||||
if test_if_required and not test_if_required(conf):
|
if test_if_required and not test_if_required(conf):
|
||||||
# The config says this file is not required, so we won't even check it.
|
# The config says this file is not required, so we won't even check it.
|
||||||
|
@ -40,8 +40,7 @@ class CheckDependenciesTestCase(unittest.TestCase):
|
|||||||
machine.return_value = 'x86_64'
|
machine.return_value = 'x86_64'
|
||||||
with mock.patch('os.path.exists') as exists:
|
with mock.patch('os.path.exists') as exists:
|
||||||
exists.side_effect = self.dont_find([])
|
exists.side_effect = self.dont_find([])
|
||||||
with mock.patch('__builtin__.__import__'):
|
result = checks.check({})
|
||||||
result = checks.check({})
|
|
||||||
|
|
||||||
self.assertEqual('', out.getvalue())
|
self.assertEqual('', out.getvalue())
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
@ -56,8 +55,7 @@ class CheckDependenciesTestCase(unittest.TestCase):
|
|||||||
machine.return_value = 'x86_64'
|
machine.return_value = 'x86_64'
|
||||||
with mock.patch('os.path.exists') as exists:
|
with mock.patch('os.path.exists') as exists:
|
||||||
exists.side_effect = self.dont_find(['/usr/bin/jigdo-lite'])
|
exists.side_effect = self.dont_find(['/usr/bin/jigdo-lite'])
|
||||||
with mock.patch('__builtin__.__import__'):
|
result = checks.check(conf)
|
||||||
result = checks.check(conf)
|
|
||||||
|
|
||||||
self.assertEqual('', out.getvalue())
|
self.assertEqual('', out.getvalue())
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
@ -72,8 +70,7 @@ class CheckDependenciesTestCase(unittest.TestCase):
|
|||||||
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
||||||
with mock.patch('os.path.exists') as exists:
|
with mock.patch('os.path.exists') as exists:
|
||||||
exists.side_effect = self.dont_find(['/usr/bin/isohybrid'])
|
exists.side_effect = self.dont_find(['/usr/bin/isohybrid'])
|
||||||
with mock.patch('__builtin__.__import__'):
|
result = checks.check(conf)
|
||||||
result = checks.check(conf)
|
|
||||||
|
|
||||||
self.assertEqual('', out.getvalue())
|
self.assertEqual('', out.getvalue())
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
@ -87,8 +84,7 @@ class CheckDependenciesTestCase(unittest.TestCase):
|
|||||||
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
||||||
with mock.patch('os.path.exists') as exists:
|
with mock.patch('os.path.exists') as exists:
|
||||||
exists.side_effect = self.dont_find(['/usr/bin/isohybrid'])
|
exists.side_effect = self.dont_find(['/usr/bin/isohybrid'])
|
||||||
with mock.patch('__builtin__.__import__'):
|
result = checks.check(conf)
|
||||||
result = checks.check(conf)
|
|
||||||
|
|
||||||
self.assertEqual('', out.getvalue())
|
self.assertEqual('', out.getvalue())
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
@ -105,8 +101,7 @@ class CheckDependenciesTestCase(unittest.TestCase):
|
|||||||
machine.return_value = 'armhfp'
|
machine.return_value = 'armhfp'
|
||||||
with mock.patch('os.path.exists') as exists:
|
with mock.patch('os.path.exists') as exists:
|
||||||
exists.side_effect = self.dont_find(['/usr/bin/isohybrid'])
|
exists.side_effect = self.dont_find(['/usr/bin/isohybrid'])
|
||||||
with mock.patch('__builtin__.__import__'):
|
result = checks.check(conf)
|
||||||
result = checks.check(conf)
|
|
||||||
|
|
||||||
self.assertRegexpMatches(out.getvalue(), r'^Not checking.*Expect failures.*$')
|
self.assertRegexpMatches(out.getvalue(), r'^Not checking.*Expect failures.*$')
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
@ -119,8 +114,7 @@ class CheckDependenciesTestCase(unittest.TestCase):
|
|||||||
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
||||||
with mock.patch('os.path.exists') as exists:
|
with mock.patch('os.path.exists') as exists:
|
||||||
exists.side_effect = self.dont_find(['/usr/bin/isohybrid'])
|
exists.side_effect = self.dont_find(['/usr/bin/isohybrid'])
|
||||||
with mock.patch('__builtin__.__import__'):
|
result = checks.check(conf)
|
||||||
result = checks.check(conf)
|
|
||||||
|
|
||||||
self.assertEqual('', out.getvalue())
|
self.assertEqual('', out.getvalue())
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
@ -133,8 +127,7 @@ class CheckDependenciesTestCase(unittest.TestCase):
|
|||||||
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
||||||
with mock.patch('os.path.exists') as exists:
|
with mock.patch('os.path.exists') as exists:
|
||||||
exists.side_effect = self.dont_find(['/usr/bin/genisoimage'])
|
exists.side_effect = self.dont_find(['/usr/bin/genisoimage'])
|
||||||
with mock.patch('__builtin__.__import__'):
|
result = checks.check(conf)
|
||||||
result = checks.check(conf)
|
|
||||||
|
|
||||||
self.assertEqual('', out.getvalue())
|
self.assertEqual('', out.getvalue())
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
@ -149,8 +142,7 @@ class CheckDependenciesTestCase(unittest.TestCase):
|
|||||||
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
||||||
with mock.patch('os.path.exists') as exists:
|
with mock.patch('os.path.exists') as exists:
|
||||||
exists.side_effect = self.dont_find(['/usr/bin/genisoimage'])
|
exists.side_effect = self.dont_find(['/usr/bin/genisoimage'])
|
||||||
with mock.patch('__builtin__.__import__'):
|
result = checks.check(conf)
|
||||||
result = checks.check(conf)
|
|
||||||
|
|
||||||
self.assertIn('genisoimage', out.getvalue())
|
self.assertIn('genisoimage', out.getvalue())
|
||||||
self.assertFalse(result)
|
self.assertFalse(result)
|
||||||
@ -159,8 +151,7 @@ class CheckDependenciesTestCase(unittest.TestCase):
|
|||||||
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
||||||
with mock.patch('os.path.exists') as exists:
|
with mock.patch('os.path.exists') as exists:
|
||||||
exists.side_effect = self.dont_find(['/usr/bin/modifyrepo'])
|
exists.side_effect = self.dont_find(['/usr/bin/modifyrepo'])
|
||||||
with mock.patch('__builtin__.__import__'):
|
result = checks.check({})
|
||||||
result = checks.check({})
|
|
||||||
|
|
||||||
self.assertIn('createrepo', out.getvalue())
|
self.assertIn('createrepo', out.getvalue())
|
||||||
self.assertFalse(result)
|
self.assertFalse(result)
|
||||||
@ -169,8 +160,7 @@ class CheckDependenciesTestCase(unittest.TestCase):
|
|||||||
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
||||||
with mock.patch('os.path.exists') as exists:
|
with mock.patch('os.path.exists') as exists:
|
||||||
exists.side_effect = self.dont_find(['/usr/bin/createrepo_c'])
|
exists.side_effect = self.dont_find(['/usr/bin/createrepo_c'])
|
||||||
with mock.patch('__builtin__.__import__'):
|
result = checks.check({})
|
||||||
result = checks.check({})
|
|
||||||
|
|
||||||
self.assertIn('createrepo_c', out.getvalue())
|
self.assertIn('createrepo_c', out.getvalue())
|
||||||
self.assertFalse(result)
|
self.assertFalse(result)
|
||||||
@ -183,8 +173,7 @@ class CheckDependenciesTestCase(unittest.TestCase):
|
|||||||
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
with mock.patch('sys.stdout', new_callable=StringIO.StringIO) as out:
|
||||||
with mock.patch('os.path.exists') as exists:
|
with mock.patch('os.path.exists') as exists:
|
||||||
exists.side_effect = self.dont_find(['/usr/bin/createrepo_c'])
|
exists.side_effect = self.dont_find(['/usr/bin/createrepo_c'])
|
||||||
with mock.patch('__builtin__.__import__'):
|
result = checks.check(conf)
|
||||||
result = checks.check(conf)
|
|
||||||
|
|
||||||
self.assertNotIn('createrepo_c', out.getvalue())
|
self.assertNotIn('createrepo_c', out.getvalue())
|
||||||
self.assertTrue(result)
|
self.assertTrue(result)
|
||||||
|
Loading…
Reference in New Issue
Block a user