summaryrefslogtreecommitdiff
path: root/scripts/util.py
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2016-03-04 15:05:03 -0500
committerDaniil Baturin <daniil@baturin.org>2016-03-04 15:05:03 -0500
commit08a6856b3c8f3146343647f996fca9c48fb4e960 (patch)
tree1166dee4b9cee8884b3bdf3fb02d5297cac3877a /scripts/util.py
parentc6bca34587458c1abee07ff7af7d618ea2f40b9c (diff)
downloadvyos-build-08a6856b3c8f3146343647f996fca9c48fb4e960.tar.gz
vyos-build-08a6856b3c8f3146343647f996fca9c48fb4e960.zip
Factor out dependency checking functions to its own class (ref T9).
Diffstat (limited to 'scripts/util.py')
-rw-r--r--scripts/util.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/scripts/util.py b/scripts/util.py
index 0037767..7cc3336 100644
--- a/scripts/util.py
+++ b/scripts/util.py
@@ -19,6 +19,7 @@
import sys
import os
+from distutils.spawn import find_executable
import defaults
@@ -27,3 +28,38 @@ def check_build_config():
print("Build config file ({file}) does not exist".format(file=defaults.BUILD_CONFIG))
print("If you are running this script by hand, you should better not. Run 'make iso' instead.")
sys.exit(1)
+
+
+class DependencyChecker(object):
+ def __init__(self, spec):
+ missing_packages = self._get_missing_packages(spec['packages'])
+ missing_binaries = self._get_missing_binaries(spec['binaries'])
+ self.__missing = {'packages': missing_packages, 'binaries': missing_binaries}
+
+
+ def _package_installed(self, name):
+ result = os.system("dpkg-query -W --showformat='${{Status}}\n' {name} 2>&1 | grep 'install ok installed' >/dev/null".format(name=name))
+ return True if result == 0 else False
+
+ def _get_missing_packages(self, packages):
+ missing_packages = []
+ for p in packages:
+ if not self._package_installed(p):
+ missing_packages.append(p)
+ return missing_packages
+
+ def _get_missing_binaries(self, binaries):
+ missing_binaries = []
+ for b in binaries:
+ if not find_executable(b):
+ missing_binaries.append(b)
+ return missing_binaries
+
+ def get_missing_dependencies(self):
+ if self.__missing['packages'] or self.__missing['binaries']:
+ return self.__missing
+ return None
+
+ def print_missing_deps(self):
+ print("Missing packages: " + " ".join(self.__missing['packages']))
+ print("Missing binaries: " + " ".join(self.__missing['binaries']))