diff options
author | Daniil Baturin <daniil@baturin.org> | 2016-03-04 15:05:03 -0500 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2016-03-04 15:05:03 -0500 |
commit | 08a6856b3c8f3146343647f996fca9c48fb4e960 (patch) | |
tree | 1166dee4b9cee8884b3bdf3fb02d5297cac3877a /scripts/check-vm-build-env | |
parent | c6bca34587458c1abee07ff7af7d618ea2f40b9c (diff) | |
download | vyos-build-08a6856b3c8f3146343647f996fca9c48fb4e960.tar.gz vyos-build-08a6856b3c8f3146343647f996fca9c48fb4e960.zip |
Factor out dependency checking functions to its own class (ref T9).
Diffstat (limited to 'scripts/check-vm-build-env')
-rwxr-xr-x | scripts/check-vm-build-env | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/scripts/check-vm-build-env b/scripts/check-vm-build-env index 290b28c8..47ec5922 100755 --- a/scripts/check-vm-build-env +++ b/scripts/check-vm-build-env @@ -21,41 +21,31 @@ import os import sys -from distutils.spawn import find_executable -required_packages = [ - 'make', - 'qemu-system-x86', - 'qemu-utils' -] +import util +deps = { + 'packages': [ + 'make', + 'qemu-system-x86', + 'qemu-utils' + ], + 'binaries': ['packer'] +} -def is_installed(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 +print("Checking if packages required for VyOS image build are installed") +checker = util.DependencyChecker(deps) -missing_packages = [] - -print("Checking if packages required for VyOS VM image build are installed") - -for p in required_packages: - if not is_installed(p): - missing_packages.append(p) - -if missing_packages: - print("Your system does not have some of the required packages installed.") - print("Please install the following packages:") - print(" ".join(missing_packages)) - sys.exit(1) -else: - print("All required packages are installed") - -if find_executable("packer"): - print("Your system has Packer.") +missing = checker.get_missing_dependencies() +if not missing: + print("All dependencies are installed") + sys.exit(0) else: - print("Your system does not have Packer.") - print("Please install Packer from https://www.packer.io/downloads.html.") + checker.print_missing_deps() + if 'packer' in missing['binaries']: + print("Your system does not have Packer.") + print("Please install Packer from https://www.packer.io/downloads.html.") sys.exit(1) sys.exit(0) |