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 ..plugin import construct_graph, IsSubclass
13 # ('csvdriver', True),
15 # ('hemingclamp', True),
18 # ('mfp1dexport', True),
20 # ('picoforce', True),
21 # ('picoforcealt', True),
24 """List of driver modules and whether they should be included by
25 default. TODO: autodiscovery
28 DRIVER_SETTING_SECTION = 'drivers'
29 """Name of the config section which controls driver selection.
34 """Base class for file format drivers.
36 :attr:`name` identifies your driver, and should match the module
39 def __init__(self, name):
41 self.setting_section = '%s driver' % self.name
43 def dependencies(self):
44 """Return a list of :class:`Driver`\s we require."""
47 def default_settings(self):
48 """Return a list of :class:`hooke.config.Setting`\s for any
49 configurable driver settings.
51 The suggested section setting is::
53 Setting(section=self.setting_section, help=self.__doc__)
57 def is_me(self, path):
58 """Read the file and return True if the filetype can be
59 managed by the driver. Otherwise return False.
64 """Read data from `path` and return a
65 (:class:`hooke.curve.Data`, `info`) tuple.
67 The `info` :class:`dict` must contain values for the keys:
68 'filetype' and 'experiment'. See :class:`hooke.curve.Curve`
71 raise NotImplementedError
73 # Construct driver dependency graph and load default drivers.
75 DRIVER_GRAPH = construct_graph(
76 this_modname=__name__,
77 submodnames=[name for name,include in DRIVER_MODULES],
78 class_selector=IsSubclass(Driver, blacklist=[Driver]))
79 """Topologically sorted list of all possible :class:`Driver`\s.
82 def default_settings():
83 settings = [Setting(DRIVER_SETTING_SECTION,
84 help='Enable/disable default drivers.')]
85 for dnode in DRIVER_GRAPH:
87 default_include = [di for mod_name,di in DRIVER_MODULES
88 if mod_name == driver.name][0]
89 help = driver.__doc__.split('\n', 1)[0]
90 settings.append(Setting(
91 section=DRIVER_SETTING_SECTION,
93 value=str(default_include),
96 for dnode in DRIVER_GRAPH:
98 settings.extend(driver.default_settings())