Add dependency checking to hooke.plugin.load_graph
[hooke.git] / hooke / plugin / __init__.py
index 4249730e52ab9a3ecb0e88e455c8057991ea9d54..052284d84317dd3c3c86c8b4ae7b2e319b6ae544 100644 (file)
@@ -2,15 +2,15 @@
 #
 # This file is part of Hooke.
 #
-# Hooke is free software: you can redistribute it and/or
-# modify it under the terms of the GNU Lesser General Public
-# License as published by the Free Software Foundation, either
-# version 3 of the License, or (at your option) any later version.
+# Hooke is free software: you can redistribute it and/or modify it
+# under the terms of the GNU Lesser General Public License as
+# published by the Free Software Foundation, either version 3 of the
+# License, or (at your option) any later version.
 #
-# Hooke is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU Lesser General Public License for more details.
+# Hooke is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General
+# Public License for more details.
 #
 # You should have received a copy of the GNU Lesser General Public
 # License along with Hooke.  If not, see
@@ -23,6 +23,7 @@ All of the science happens in here.
 """
 
 import ConfigParser as configparser
+import logging
 
 from ..config import Setting
 from ..util.pluggable import IsSubclass, construct_graph
@@ -58,8 +59,10 @@ BUILTIN_MODULES = [
     'config',
     'curve',
     'debug',
+    'license',
     'note',
     'playlist',
+    'playlists',
     'system',
     ]
 """List of builtin modules.  TODO: autodiscovery
@@ -76,7 +79,9 @@ class Plugin (object):
     """A pluggable collection of Hooke commands.
 
     Fulfills the same role for Hooke that a software package does for
-    an operating system.
+    an operating system: contains a chunk of related commands and
+    routines.  Command configuration also happens on the `Plugin`
+    level, with per-plugin sections in the configuration file.
     """
     def __init__(self, name):
         self.name = name
@@ -103,6 +108,7 @@ class Plugin (object):
         """
         return list(self._commands)
 
+
 class Builtin (Plugin):
     """A required collection of Hooke commands.
 
@@ -111,6 +117,7 @@ class Builtin (Plugin):
     """
     pass
 
+
 # Plugin utility functions
 
 def argument_to_setting(section_name, argument):
@@ -124,6 +131,7 @@ def argument_to_setting(section_name, argument):
     return Setting(section_name, option=argument.name, value=argument.default,
                    help=argument._help)
 
+
 # Construct plugin dependency graph and load plugin instances.
 
 PLUGIN_GRAPH = construct_graph(
@@ -156,6 +164,7 @@ def default_settings():
     return settings
 
 def load_graph(graph, config, include_section):
+    enabled = {}
     items = []
     for node in graph:
         item = node.data
@@ -163,7 +172,17 @@ def load_graph(graph, config, include_section):
             include = config.getboolean(include_section, item.name)
         except configparser.NoOptionError:
             include = True # non-optional include (e.g. a Builtin)
+        enabled[item.name] = include
+        print item.name, include
         if include == True:
+            for dependency in node:
+                if enabled.get(dependency.data.name, None) != True:
+                    log = logging.getLogger('hooke')
+                    log.warn(
+                     'could not setup plugin %s.  unsatisfied dependency on %s'.
+                     % (item.name, dependency.data.name))
+                    enabled[item.name] = False
+                    continue
             try:
                 item.config = dict(config.items(item.setting_section))
             except configparser.NoSectionError: