]> git.ipfire.org Git - people/stevee/ddns.git/commitdiff
Add runtime check for providers if all dependencies are met
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 14 Sep 2014 19:54:13 +0000 (19:54 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 14 Sep 2014 19:54:13 +0000 (19:54 +0000)
configure.ac
src/ddns/__init__.py
src/ddns/providers.py

index 124a56255590a28081fa8c97357094e9bfb2df27..a8920957b594e459740d718104a682346eba4521 100644 (file)
@@ -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}
 ])
index 84b8c80043a2378284afc254585d4c080b72b837..7f2729c2c8c0cc93e09e46ec343fce6804664276 100644 (file)
@@ -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)
index b66afc51bc4dae7da2fa750553bb7fffd5135a4f..2c54f5a3efccbc55418aed5ab826598149777d40 100644 (file)
@@ -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()