Add support for plugin "libraries" that do not specifically tie into the plugin system and can be imported by other plugins.

svn: r11758
This commit is contained in:
Brian Matherly 2009-01-30 02:16:00 +00:00
parent 625b1eb379
commit 497e8d8233
4 changed files with 24 additions and 40 deletions

View File

@ -35,7 +35,7 @@ class ExportPlugin(Plugin):
@param name: A friendly name to call this plugin.
Example: "GEDCOM Export"
@type name: string
@param description: An short description of the plugin.
@param description: A short description of the plugin.
Example: "This plugin will export a GEDCOM file from database"
@type description: string
@param export_function: A function to call to perform the export.
@ -55,27 +55,10 @@ class ExportPlugin(Plugin):
@type config: tuple (??,??)
@return: nothing
"""
Plugin.__init__(self, name, description)
self.__name = name
Plugin.__init__(self, name, description, export_function.__module__)
self.__export_func = export_function
self.__extension = extension
self.__config = config
def get_module_name(self):
"""
Get the name of the module that this plugin lives in.
@return: a string representing the name of the module for this plugin
"""
return self.__export_func.__module__
def get_name(self):
"""
Get the short name for this plugins.
@return: str
"""
return self.__name
def get_export_function(self):
"""

View File

@ -34,7 +34,7 @@ class ImportPlugin(Plugin):
@param name: A friendly name to call this plugin.
Example: "GEDCOM Import"
@type name: string
@param description: An short description of the plugin.
@param description: A short description of the plugin.
Example: "This plugin will import a GEDCOM file into a database"
@type description: string
@param import_function: A function to call to perform the import.
@ -52,18 +52,10 @@ class ImportPlugin(Plugin):
@type extension: str
@return: nothing
"""
Plugin.__init__(self, name, description)
Plugin.__init__(self, name, description, import_function.__module__ )
self.__import_func = import_function
self.__extension = extension
def get_module_name(self):
"""
Get the name of the module that this plugin lives in.
@return: a string representing the name of the module for this plugin
"""
return self.__import_func.__module__
def get_import_function(self):
"""
Get the import function for this plugins.

View File

@ -95,6 +95,7 @@ class PluginManager(gen.utils.Callback):
self.__tool_list = []
self.__import_plugins = []
self.__export_plugins = []
self.__general_plugins = []
self.__attempt_list = []
self.__loaddir_list = []
self.__textdoc_list = []
@ -129,12 +130,12 @@ class PluginManager(gen.utils.Callback):
# have a .py extention, and attempt to load the file. If it succeeds,
# add it to the success_list list. If it fails, add it to the _failure
# list
for (dirpath, dirnames, filenames) in os.walk(direct):
# add the directory to the python search path
sys.path.append(dirpath)
for (dirpath, dirnames, filenames) in os.walk(direct):
# if the path has not already been loaded, save it in the
# loaddir_list list for use on reloading.
if dirpath not in self.__loaddir_list:
@ -275,10 +276,12 @@ class PluginManager(gen.utils.Callback):
"""
if isinstance(plugin, gen.plug.ImportPlugin):
self.__import_plugins.append(plugin)
self.__mod2text[plugin.get_module_name()] = plugin.get_description()
if isinstance(plugin, gen.plug.ExportPlugin):
elif isinstance(plugin, gen.plug.ExportPlugin):
self.__export_plugins.append(plugin)
self.__mod2text[plugin.get_module_name()] = plugin.get_description()
elif isinstance(plugin, gen.plug.Plugin):
self.__general_plugins.append(plugin)
self.__mod2text[plugin.get_module_name()] = plugin.get_description()
def get_import_plugins(self):
"""
@ -540,10 +543,12 @@ class PluginManager(gen.utils.Callback):
for filename, junk in self.__failmsg_list
]
self.__general_plugins[:] = [ item for item in self.__export_plugins
if item.get_module_name() not in self.__general_plugins ][:]
self.__export_plugins[:] = [ item for item in self.__export_plugins
if item.get_module_name not in failed_module_names ][:]
if item.get_module_name() not in failed_module_names ][:]
self.__import_plugins[:] = [ item for item in self.__import_plugins
if item.get_module_name not in failed_module_names ][:]
if item.get_module_name() not in failed_module_names ][:]
self.__tool_list[:] = [ item for item in self.__tool_list
if item[0].__module__ not in failed_module_names ][:]
self.__cli_tool_list[:] = [ item for item in self.__cli_tool_list

View File

@ -28,18 +28,22 @@ class Plugin:
This class serves as a base class for all plugins that can be registered
with the plugin manager
"""
def __init__(self, name, description):
def __init__(self, name, description, module_name):
"""
@param name: A friendly name to call this plugin.
Example: "GEDCOM Import"
@type name: string
@param description: An short description of the plugin.
@param description: A short description of the plugin.
Example: "This plugin will import a GEDCOM file into a database"
@type description: string
@param module_name: The name of the module that contains this plugin.
Example: "gedcom"
@type module_name: string
@return: nothing
"""
self.__name = name
self.__desc = description
self.__mod_name = module_name
def get_name(self):
"""
@ -63,5 +67,5 @@ class Plugin:
@return: a string representing the name of the module for this plugin
"""
raise NotImplementedError
return self.__mod_name