1 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
3 # This file is part of Hooke.
5 # Hooke is free software: you can redistribute it and/or
6 # modify it under the terms of the GNU Lesser General Public
7 # License as published by the Free Software Foundation, either
8 # version 3 of the License, or (at your option) any later version.
10 # Hooke is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU Lesser General Public License for more details.
15 # You should have received a copy of the GNU Lesser General Public
16 # License along with Hooke. If not, see
17 # <http://www.gnu.org/licenses/>.
19 """The `plugin` module provides optional submodules that add new Hooke
22 All of the science happens in here.
25 import ConfigParser as configparser
27 from ..config import Setting
28 from ..util.pluggable import IsSubclass, construct_graph
33 # ('curvetools', True),
36 # ('flatfilts-rolf', True),
37 # ('flatfilts', True),
38 # ('generalclamp', True),
39 # ('generaltccd', True),
40 # ('generalvclamp', True),
43 # ('massanalysis', True),
44 # ('multidistance', True),
48 # ('procplots', True),
50 # ('showconvoluted', True),
51 # ('superimpose', True),
54 """List of plugin modules and whether they should be included by
55 default. TODO: autodiscovery
66 """List of builtin modules. TODO: autodiscovery
69 PLUGIN_SETTING_SECTION = 'plugins'
70 """Name of the config section which controls plugin selection.
74 # Plugins and settings
76 class Plugin (object):
77 """A pluggable collection of Hooke commands.
79 Fulfills the same role for Hooke that a software package does for
82 def __init__(self, name):
84 self.setting_section = '%s plugin' % self.name
87 def dependencies(self):
88 """Return a list of :class:`Plugin`\s we require."""
91 def default_settings(self):
92 """Return a list of :class:`hooke.config.Setting`\s for any
93 configurable plugin settings.
95 The suggested section setting is::
97 Setting(section=self.setting_section, help=self.__doc__)
102 """Return a list of :class:`hooke.command.Command`\s provided.
106 class Builtin (Plugin):
107 """A required collection of Hooke commands.
109 These "core" plugins provide essential administrative commands
110 (playlist handling, etc.).
114 # Construct plugin dependency graph and load plugin instances.
116 PLUGIN_GRAPH = construct_graph(
117 this_modname=__name__,
118 submodnames=[name for name,include in PLUGIN_MODULES] + BUILTIN_MODULES,
119 class_selector=IsSubclass(Plugin, blacklist=[Plugin, Builtin]))
120 """Topologically sorted list of all possible :class:`Plugin`\s and
124 def default_settings():
125 settings = [Setting(PLUGIN_SETTING_SECTION,
126 help='Enable/disable default plugins.')]
127 for pnode in PLUGIN_GRAPH:
128 if pnode.data.name in BUILTIN_MODULES:
129 continue # builtin inclusion is not optional
131 default_include = [di for mod_name,di in PLUGIN_MODULES
132 if mod_name == plugin.name][0]
133 help = 'Commands: ' + ', '.join([c.name for c in plugin.commands()])
134 settings.append(Setting(
135 section=PLUGIN_SETTING_SECTION,
137 value=str(default_include),
140 for pnode in PLUGIN_GRAPH:
142 settings.extend(plugin.default_settings())
145 def load_graph(graph, config, include_section):
150 include = config.getboolean(include_section, item.name)
151 except configparser.NoOptionError:
152 include = True # non-optional include (e.g. a Builtin)
155 item.config = dict(config.items(item.setting_section))
156 except configparser.NoSectionError: