]> git.ipfire.org Git - ddns.git/blobdiff - src/ddns/__init__.py
Add runtime check for providers if all dependencies are met
[ddns.git] / src / ddns / __init__.py
index 78009e33e98cf1a30531e4fc1ff15074007e37ef..7f2729c2c8c0cc93e09e46ec343fce6804664276 100644 (file)
@@ -28,8 +28,10 @@ from i18n import _
 logger = logging.getLogger("ddns.core")
 logger.propagate = 1
 
+import database
 import providers
 
+from .errors import *
 from .system import DDNSSystem
 
 # Setup the logger.
@@ -41,6 +43,8 @@ def setup_logging():
        handler = logging.handlers.SysLogHandler(address="/dev/log",
                facility=logging.handlers.SysLogHandler.LOG_DAEMON
        )
+       formatter = logging.Formatter("ddns[%(process)d]: %(message)s")
+       handler.setFormatter(formatter)
        handler.setLevel(logging.INFO)
        rootlogger.addHandler(handler)
 
@@ -73,6 +77,9 @@ class DDNSCore(object):
                # Add the system class.
                self.system = DDNSSystem(self)
 
+               # Open the database.
+               self.db = database.DDNSDatabase(self, "/var/lib/ddns.db")
+
        def get_provider_names(self):
                """
                        Returns a list of names of all registered providers.
@@ -82,12 +89,17 @@ class DDNSCore(object):
        def load_configuration(self, filename):
                logger.debug(_("Loading configuration file %s") % filename)
 
-               configs = ConfigParser.SafeConfigParser()
+               configs = ConfigParser.RawConfigParser()
                configs.read([filename,])
 
                # First apply all global configuration settings.
-               for k, v in configs.items("config"):
-                       self.settings[k] = v
+               try:
+                       for k, v in configs.items("config"):
+                               self.settings[k] = v
+
+               # Allow missing config section
+               except ConfigParser.NoSectionError:
+                       pass
 
                for entry in configs.sections():
                        # Skip the special config section.
@@ -112,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)
@@ -155,7 +173,3 @@ class DDNSCore(object):
                except Exception, e:
                        logger.error(_("Dynamic DNS update for %(hostname)s (%(provider)s) throwed an unhandled exception:") % \
                                { "hostname" : entry.hostname, "provider" : entry.name }, exc_info=True)
-
-               else:
-                       logger.info(_("Dynamic DNS update for %(hostname)s (%(provider)s) successful") % \
-                               { "hostname" : entry.hostname, "provider" : entry.name })