def _load_plugin_class(self, filepath):
"""
Loads the plugin method and sets the self.plugin to refer to it.
:param filepath: path to the file containing the python function
"""
expected_class = 'ObservationUpdater'
mod_name, file_ext = os.path.splitext(os.path.split(filepath)[-1])
if file_ext.lower() == '.pyc':
py_mod = imp.load_compiled(mod_name, filepath)
else:
py_mod = imp.load_source(mod_name, filepath)
if hasattr(py_mod, expected_class):
self.plugin = getattr(py_mod, expected_class)()
else:
raise Exception(
'Cannot find ObservationUpdater class in pluging file ' +
filepath)
if not hasattr(self.plugin, 'update'):
raise Exception(
'Cannot find update method in plugin class ' + filepath)
评论列表
文章目录