0770f9e6f815fbaa81ea361fb6f1eb5a569b7993
[hooke.git] / hooke / plugin / __init__.py
1 #!/usr/bin/env python
2 """The plugin module provides optional submodules that add new Hooke
3 commands.
4
5 All of the science happens in here.
6 """
7
8 import os.path
9
10 from ..config import Setting
11 from ..util.graph import Node, Graph
12
13 PLUGIN_MODULES = [
14     ('autopeak', True),
15     ('curvetools', True),
16     ('cut', True),
17     ('fit', True),
18     ('flatfilts-rolf', True),
19     ('flatfilts', True),
20     ('generalclamp', True),
21     ('generaltccd', True),
22     ('generalvclamp', True),
23     ('jumpstat', True),
24     ('macro', True),
25     ('massanalysis', True),
26     ('multidistance', True),
27     ('multifit', True),
28     ('pcluster', True),
29     ('procplots', True),
30     ('review', True),
31     ('showconvoluted', True),
32     ('superimpose', True),
33     ('tutorial', True),
34     ('viewer', True),
35     ]
36 """List of plugin modules and whether they should be included by
37 default.
38 """
39
40 def Plugin (object):
41     """The pluggable collection of Hooke commands.
42
43     Fulfills the same role for Hooke that a software package does for
44     an operating system.
45     """
46     name = "base plugin"
47
48     def dependencies(self):
49         """Return a list of Plugins we require."""
50         return []
51
52     def default_settings(self):
53         """Return a list of hooke.config.Settings() for any
54         configurable module settings."""
55         return []
56
57     def commands(self):
58         """Return a list of Commands provided."""
59         return []
60
61 PLUGINS = {}
62 """(name,instance) :class:`dict` of all possible :class:`Plugin`\s.
63 """
64
65 print __name__
66 for plugin_modname,value in PLUGIN_MODULES:
67     this_mod = __import__(__name__, fromlist=[plugin_modname])
68     plugin_mod = getattr(this_mod, plugin_modname)
69     for objname in dir(plugin_mod):
70         obj = getattr(plugin_mod, objname)
71         if type(obj) == Plugin:
72             obj.module_name = plugin_modname
73             PLUGINS[p.name] = p
74
75 PLUGIN_GRAPH = Graph([Node(
76             [PLUGINS[name] for name in p.dependencies()]
77             )])
78 PLUGIN_GRAPH.topological_sort()
79
80
81 def default_settings(self):
82     settings = [Setting(
83             'plugins', help='Enable/disable default plugins.')]
84     for pnode in PLUGIN_GRAPH:
85         settings.append(Setting(p.name, str(PLUGIN_MODULES[p.module_name][1])))      
86     for pnode in PLUGIN_GRAPH:
87         plugin = pnode.data
88         settings.extend(plugin.default_settings())
89     return settings
90
91 class Command (object):
92     pass