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
65 """List of builtin modules. TODO: autodiscovery
68 PLUGIN_SETTING_SECTION = 'plugins'
69 """Name of the config section which controls plugin selection.
73 # Plugins and settings
75 class Plugin (object):
76 """A pluggable collection of Hooke commands.
78 Fulfills the same role for Hooke that a software package does for
81 def __init__(self, name):
83 self.setting_section = '%s plugin' % self.name
86 def dependencies(self):
87 """Return a list of :class:`Plugin`\s we require."""
90 def default_settings(self):
91 """Return a list of :class:`hooke.config.Setting`\s for any
92 configurable plugin settings.
94 The suggested section setting is::
96 Setting(section=self.setting_section, help=self.__doc__)
101 """Return a list of :class:`hooke.command.Command`\s provided.
105 class Builtin (Plugin):
106 """A required collection of Hooke commands.
108 These "core" plugins provide essential administrative commands
109 (playlist handling, etc.).
113 # Construct plugin dependency graph and load plugin instances.
115 PLUGIN_GRAPH = construct_graph(
116 this_modname=__name__,
117 submodnames=[name for name,include in PLUGIN_MODULES] + BUILTIN_MODULES,
118 class_selector=IsSubclass(Plugin, blacklist=[Plugin, Builtin]))
119 """Topologically sorted list of all possible :class:`Plugin`\s and
123 def default_settings():
124 settings = [Setting(PLUGIN_SETTING_SECTION,
125 help='Enable/disable default plugins.')]
126 for pnode in PLUGIN_GRAPH:
127 if pnode.data.name in BUILTIN_MODULES:
128 continue # builtin inclusion is not optional
130 default_include = [di for mod_name,di in PLUGIN_MODULES
131 if mod_name == plugin.name][0]
132 help = 'Commands: ' + ', '.join([c.name for c in plugin.commands()])
133 settings.append(Setting(
134 section=PLUGIN_SETTING_SECTION,
136 value=str(default_include),
139 for pnode in PLUGIN_GRAPH:
141 settings.extend(plugin.default_settings())
144 def load_graph(graph, config, include_section):
149 include = config.getboolean(include_section, item.name)
150 except configparser.NoOptionError:
151 include = True # non-optional include (e.g. a Builtin)
154 item.config = dict(config.items(item.setting_section))
155 except configparser.NoSectionError: