From: Michael Tremer Date: Sun, 14 Sep 2014 19:54:13 +0000 (+0000) Subject: Add runtime check for providers if all dependencies are met X-Git-Tag: 005~8 X-Git-Url: http://git.ipfire.org/?p=ddns.git;a=commitdiff_plain;h=64d3fad4f0e7f6715f9fa77c92bd784f68395688 Add runtime check for providers if all dependencies are met --- diff --git a/configure.ac b/configure.ac index 124a562..a892095 100644 --- a/configure.ac +++ b/configure.ac @@ -54,12 +54,6 @@ AC_PROG_SED # Python AM_PATH_PYTHON([2.7]) -# BIND nsupdate -AC_CHECK_TOOL([NSUPDATE], [nsupdate]) -if test -z "${NSUPDATE}"; then - AC_MSG_ERROR([*** nsupdate not found]) -fi - save_LIBS="$LIBS" AC_CONFIG_FILES([ @@ -74,6 +68,4 @@ AC_MSG_RESULT([ prefix : ${prefix} sysconfdir : ${sysconfdir} - - nsupdate : ${NSUPDATE} ]) diff --git a/src/ddns/__init__.py b/src/ddns/__init__.py index 84b8c80..7f2729c 100644 --- a/src/ddns/__init__.py +++ b/src/ddns/__init__.py @@ -124,6 +124,12 @@ class DDNSCore(object): logger.warning("Could not find provider '%s' for entry '%s'." % (provider, entry)) continue + # Check if the provider is actually supported and if there are + # some dependencies missing on this system. + if not provider.supported(): + logger.warning("Provider '%s' is known, but not supported on this machine" % (provider.name)) + continue + # Create an instance of the provider object with settings from the # configuration file. entry = provider(self, **settings) diff --git a/src/ddns/providers.py b/src/ddns/providers.py index b66afc5..2c54f5a 100644 --- a/src/ddns/providers.py +++ b/src/ddns/providers.py @@ -21,6 +21,7 @@ import datetime import logging +import os import subprocess import urllib2 import xml.dom.minidom @@ -84,6 +85,14 @@ class DDNSProvider(object): _providers[provider.handle] = provider + @staticmethod + def supported(): + """ + Should be overwritten to check if the system the code is running + on has all the required tools to support this provider. + """ + return True + def __init__(self, core, **settings): self.core = core @@ -406,6 +415,19 @@ class DDNSProviderBindNsupdate(DDNSProvider): DEFAULT_TTL = 60 + @staticmethod + def supported(): + # Search if the nsupdate utility is available + paths = os.environ.get("PATH") + + for path in paths.split(":"): + executable = os.path.join(path, "nsupdate") + + if os.path.exists(executable): + return True + + return False + def update(self): scriptlet = self.__make_scriptlet()