From ef4c48cadd613a7469a34f17c0304b055b67af06 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sun, 3 May 2020 15:06:59 +0200 Subject: [PATCH] add dependency checks for #225 --- dotdrop/dotdrop.py | 9 ++++++++- dotdrop/utils.py | 11 ++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/dotdrop/dotdrop.py b/dotdrop/dotdrop.py index 4bddfe6..d600706 100644 --- a/dotdrop/dotdrop.py +++ b/dotdrop/dotdrop.py @@ -16,7 +16,7 @@ from dotdrop.installer import Installer from dotdrop.updater import Updater from dotdrop.comparator import Comparator from dotdrop.utils import get_tmpdir, remove, strip_home, \ - run, uniq_list, patch_ignores + run, uniq_list, patch_ignores, dependencies_met from dotdrop.linktypes import LinkTypes from dotdrop.exceptions import YamlException @@ -648,6 +648,13 @@ def main(): if o.debug: LOG.dbg('\n\n') + # check dependencies are met + try: + dependencies_met() + except Exception as e: + LOG.err(e) + return False + ret = True try: diff --git a/dotdrop/utils.py b/dotdrop/utils.py index b7fbce2..ee1a65d 100644 --- a/dotdrop/utils.py +++ b/dotdrop/utils.py @@ -12,7 +12,7 @@ import uuid import fnmatch import inspect import importlib -from shutil import rmtree +from shutil import rmtree, which # local import from dotdrop.logger import Logger @@ -224,3 +224,12 @@ def get_module_from_path(path): loader = importlib.machinery.SourceFileLoader(module_name, path) mod = loader.load_module() return mod + + +def dependencies_met(): + """make sure all dependencies are met""" + deps = ['file', 'diff', 'mkdir', 'cp'] + err = 'The tool \"{}\" was not found in the PATH!' + for dep in deps: + if not which(dep): + raise Exception(err.format(dep))