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 driver module provides :class:`Driver`\s for identifying and
22 This allows Hooke to be data-file agnostic. Drivers for various
23 commercial force spectroscopy microscopes are provided, and it's easy
24 to write your own to handle your lab's specific format.
27 from ..config import Setting
28 from ..util.pluggable import IsSubclass, construct_graph
32 # ('csvdriver', True),
34 # ('hemingclamp', True),
37 # ('mfp1dexport', True),
40 # ('picoforcealt', True),
44 """List of driver modules and whether they should be included by
45 default. TODO: autodiscovery
48 DRIVER_SETTING_SECTION = 'drivers'
49 """Name of the config section which controls driver selection.
54 """Base class for file format drivers.
56 :attr:`name` identifies your driver, and should match the module
59 def __init__(self, name):
61 self.setting_section = '%s driver' % self.name
63 def dependencies(self):
64 """Return a list of :class:`Driver`\s we require."""
67 def default_settings(self):
68 """Return a list of :class:`hooke.config.Setting`\s for any
69 configurable driver settings.
71 The suggested section setting is::
73 Setting(section=self.setting_section, help=self.__doc__)
77 def is_me(self, path):
78 """Read the file and return True if the filetype can be
79 managed by the driver. Otherwise return False.
84 """Read data from `path` and return a
85 ([:class:`hooke.curve.Data`, ...], `info`) tuple.
87 The `info` :class:`dict` must contain values for the keys:
88 'filetype' and 'experiment'. See :class:`hooke.curve.Curve`
91 raise NotImplementedError
93 # Construct driver dependency graph and load default drivers.
95 DRIVER_GRAPH = construct_graph(
96 this_modname=__name__,
97 submodnames=[name for name,include in DRIVER_MODULES],
98 class_selector=IsSubclass(Driver, blacklist=[Driver]))
99 """Topologically sorted list of all possible :class:`Driver`\s.
102 def default_settings():
103 settings = [Setting(DRIVER_SETTING_SECTION,
104 help='Enable/disable default drivers.')]
105 for dnode in DRIVER_GRAPH:
107 default_include = [di for mod_name,di in DRIVER_MODULES
108 if mod_name == driver.name][0]
109 help = driver.__doc__.split('\n', 1)[0]
110 settings.append(Setting(
111 section=DRIVER_SETTING_SECTION,
113 value=str(default_include),
116 for dnode in DRIVER_GRAPH:
118 settings.extend(driver.default_settings())