1 """The driver module provides :class:`Driver`\s for identifying and
4 This allows Hooke to be data-file agnostic. Drivers for various
5 commercial force spectroscopy microscopes are provided, and it's easy
6 to write your own to handle your lab's specific format.
9 from ..config import Setting
10 from ..util.pluggable import IsSubclass, construct_graph
14 # ('csvdriver', True),
16 # ('hemingclamp', True),
19 # ('mfp1dexport', True),
21 # ('picoforce', True),
22 # ('picoforcealt', True),
25 """List of driver modules and whether they should be included by
26 default. TODO: autodiscovery
29 DRIVER_SETTING_SECTION = 'drivers'
30 """Name of the config section which controls driver selection.
35 """Base class for file format drivers.
37 :attr:`name` identifies your driver, and should match the module
40 def __init__(self, name):
42 self.setting_section = '%s driver' % self.name
44 def dependencies(self):
45 """Return a list of :class:`Driver`\s we require."""
48 def default_settings(self):
49 """Return a list of :class:`hooke.config.Setting`\s for any
50 configurable driver settings.
52 The suggested section setting is::
54 Setting(section=self.setting_section, help=self.__doc__)
58 def is_me(self, path):
59 """Read the file and return True if the filetype can be
60 managed by the driver. Otherwise return False.
65 """Read data from `path` and return a
66 (:class:`hooke.curve.Data`, `info`) tuple.
68 The `info` :class:`dict` must contain values for the keys:
69 'filetype' and 'experiment'. See :class:`hooke.curve.Curve`
72 raise NotImplementedError
74 # Construct driver dependency graph and load default drivers.
76 DRIVER_GRAPH = construct_graph(
77 this_modname=__name__,
78 submodnames=[name for name,include in DRIVER_MODULES],
79 class_selector=IsSubclass(Driver, blacklist=[Driver]))
80 """Topologically sorted list of all possible :class:`Driver`\s.
83 def default_settings():
84 settings = [Setting(DRIVER_SETTING_SECTION,
85 help='Enable/disable default drivers.')]
86 for dnode in DRIVER_GRAPH:
88 default_include = [di for mod_name,di in DRIVER_MODULES
89 if mod_name == driver.name][0]
90 help = driver.__doc__.split('\n', 1)[0]
91 settings.append(Setting(
92 section=DRIVER_SETTING_SECTION,
94 value=str(default_include),
97 for dnode in DRIVER_GRAPH:
99 settings.extend(driver.default_settings())