3 """The driver module provides :class:`Driver`\s for identifying and
6 This allows Hooke to be data-file agnostic. Drivers for various
7 commercial force spectroscopy microscopes are provided, and it's easy
8 to write your own to handle your lab's specific format.
11 from ..config import Setting
12 from ..util.pluggable import IsSubclass, construct_graph
16 # ('csvdriver', True),
18 # ('hemingclamp', True),
21 # ('mfp1dexport', True),
23 # ('picoforce', True),
24 # ('picoforcealt', True),
27 """List of driver modules and whether they should be included by
28 default. TODO: autodiscovery
31 DRIVER_SETTING_SECTION = 'drivers'
32 """Name of the config section which controls driver selection.
37 """Base class for file format drivers.
39 :attr:`name` identifies your driver, and should match the module
42 def __init__(self, name):
44 self.setting_section = '%s driver' % self.name
46 def dependencies(self):
47 """Return a list of :class:`Driver`\s we require."""
50 def default_settings(self):
51 """Return a list of :class:`hooke.config.Setting`\s for any
52 configurable driver settings.
54 The suggested section setting is::
56 Setting(section=self.setting_section, help=self.__doc__)
60 def is_me(self, path):
61 """Read the file and return True if the filetype can be
62 managed by the driver. Otherwise return False.
67 """Read data from `path` and return a
68 (:class:`hooke.curve.Data`, `info`) tuple.
70 The `info` :class:`dict` must contain values for the keys:
71 'filetype' and 'experiment'. See :class:`hooke.curve.Curve`
74 raise NotImplementedError
76 # Construct driver dependency graph and load default drivers.
78 DRIVER_GRAPH = construct_graph(
79 this_modname=__name__,
80 submodnames=[name for name,include in DRIVER_MODULES],
81 class_selector=IsSubclass(Driver, blacklist=[Driver]))
82 """Topologically sorted list of all possible :class:`Driver`\s.
85 def default_settings():
86 settings = [Setting(DRIVER_SETTING_SECTION,
87 help='Enable/disable default drivers.')]
88 for dnode in DRIVER_GRAPH:
90 default_include = [di for mod_name,di in DRIVER_MODULES
91 if mod_name == driver.name][0]
92 help = driver.__doc__.split('\n', 1)[0]
93 settings.append(Setting(
94 section=DRIVER_SETTING_SECTION,
96 value=str(default_include),
99 for dnode in DRIVER_GRAPH:
101 settings.extend(driver.default_settings())