def register_a_plugin(self, plugin_cls): """register loaded plugin classes""" __file_types = [] PyexcelPluginManager.register_a_plugin(self, plugin_cls) for file_type in plugin_cls.file_types: __file_types.append(file_type) self.loaded_registry[file_type] = plugin_cls
def register_a_plugin(self, plugin_cls): """register a source plugin after it is imported""" PyexcelPluginManager.register_a_plugin(self, plugin_cls) self._register_a_plugin(plugin_cls.targets, plugin_cls.actions, plugin_cls.attributes, plugin_cls.key) for target, action in product(plugin_cls.targets, plugin_cls.actions): key = REGISTRY_KEY_FORMAT % (target, action) self.loaded_registry[key].append(plugin_cls)
def load_me_now(self, key, **keywords): """load the corresponding supporting module for each file type """ PyexcelPluginManager.load_me_now(self, key, **keywords) __key = key.lower() if __key in self.registry: for path in self.registry[__key]: self.dynamic_load_library(path) # once loaded, forgot it self.registry.pop(__key)
def __init__(self): PyexcelPluginManager.__init__(self, 'source') self.registry = defaultdict(list) self.loaded_registry = { SHEET_WRITE: [], BOOK_WRITE: [], BOOK_READ: [], SHEET_READ: [] } self.keywords = {}
def load_me_later(self, plugin_info, module_name): """map each file type against its supporting module """ PyexcelPluginManager.load_me_later(self, plugin_info, module_name) library_import_path = "%s.%s" % (module_name, plugin_info.submodule) file_types = plugin_info.file_types if isinstance(file_types, types.FunctionType): file_types = file_types() for file_type in file_types: self.registry[file_type].append( (library_import_path, plugin_info.submodule))
def load_me_now(self, key, **keywords): """get source module into memory for use""" PyexcelPluginManager.load_me_now(self, key, **keywords) selected_source = None for source in self.registry[key]: if match_potential_source(source, **keywords): self.dynamic_load_library(source['path']) selected_source = source break if selected_source: self.registry[key].remove(selected_source)
def load_me_later(self, plugin_info, module_name): """map each source with its loading requirements""" PyexcelPluginManager.load_me_later(self, plugin_info, module_name) self.register_class_meta(plugin_info) library_import_path = "%s.%s" % (module_name, plugin_info.submodule) target_action_list = product(plugin_info.targets, plugin_info.actions) for target, action in target_action_list: key = "%s-%s" % (target, action) self.registry[key].append( dict(fields=plugin_info.fields, path=library_import_path, submodule=plugin_info.submodule))
def __init__(self, name): PyexcelPluginManager.__init__(self, name) self.loaded_registry = {}
def dynamic_load_library(self, library_import_path): """custom import a module """ return PyexcelPluginManager.dynamic_load_library( self, [library_import_path])