Create a new plugin class for Import plugins.
svn: r11142
This commit is contained in:
@@ -36,7 +36,6 @@ APP_GRAMPS_XML = "application/x-gramps-xml"
|
||||
APP_GEDCOM = "application/x-gedcom"
|
||||
APP_GRAMPS_PKG = "application/x-gramps-package"
|
||||
APP_GENEWEB = "application/x-geneweb"
|
||||
APP_VCARD = ["text/x-vcard", "text/x-vcalendar"]
|
||||
|
||||
PERSON_KEY = 0
|
||||
FAMILY_KEY = 1
|
||||
|
@@ -10,7 +10,9 @@ pkgdatadir = $(datadir)/@PACKAGE@/gen/plug
|
||||
|
||||
pkgdata_PYTHON = \
|
||||
__init__.py \
|
||||
_manager.py
|
||||
_import.py \
|
||||
_manager.py \
|
||||
_plugin.py
|
||||
|
||||
pkgpyexecdir = @pkgpyexecdir@/gen/plug
|
||||
pkgpythondir = @pkgpythondir@/gen/plug
|
||||
|
@@ -21,7 +21,8 @@
|
||||
The "plug" package for handling plugins in Gramps.
|
||||
"""
|
||||
|
||||
__all__ = [ "opt" ]
|
||||
|
||||
from _plugin import Plugin
|
||||
from _manager import PluginManager
|
||||
from _import import ImportPlugin
|
||||
|
||||
__all__ = [ "menu", Plugin, PluginManager, ImportPlugin ]
|
||||
|
81
src/gen/plug/_import.py
Normal file
81
src/gen/plug/_import.py
Normal file
@@ -0,0 +1,81 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2008 Brian G. Matherly
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# $Id$
|
||||
|
||||
"""
|
||||
This module provides the Plugin class for import plugins.
|
||||
"""
|
||||
|
||||
from gen.plug import Plugin
|
||||
|
||||
class ImportPlugin(Plugin):
|
||||
"""
|
||||
This class represents a plugin for importing data into Gramps
|
||||
"""
|
||||
def __init__(self, name, description, import_function, mime_types=None):
|
||||
"""
|
||||
@param name: A friendly name to call this plugin.
|
||||
Example: "GEDCOM Import"
|
||||
@type name: string
|
||||
@param description: An 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.
|
||||
The function must take the form:
|
||||
def import_function(db, filename, callback):
|
||||
where:
|
||||
"db" is a Gramps database to import the data into
|
||||
"filename" is the file that contains data to be imported
|
||||
"callback" is a callable object that takes two parameters.
|
||||
The first parameter is a progress indicator.
|
||||
The second parameter is a text string.
|
||||
@type import_function: callable
|
||||
@param mime_types: A list of mime types that apply to the file type.
|
||||
Example: "['application/x-gramps']"
|
||||
@type mime_types: [str] (list of strings)
|
||||
@return: nothing
|
||||
"""
|
||||
Plugin.__init__(self, name, description)
|
||||
self.__import_func = import_function
|
||||
self.__mime_types = mime_types
|
||||
|
||||
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.
|
||||
|
||||
@return: the callable import_function passed into __init__
|
||||
"""
|
||||
return self.__import_func
|
||||
|
||||
def get_mime_types(self):
|
||||
"""
|
||||
Get the list of mime types that apply to the import file.
|
||||
|
||||
@return: [str] (list of strings)
|
||||
"""
|
||||
return self.__mime_types
|
@@ -52,7 +52,7 @@ import Relationship
|
||||
# Constants
|
||||
#
|
||||
#-------------------------------------------------------------------------
|
||||
_UNAVAILABLE = _("No description was provided"),
|
||||
_UNAVAILABLE = _("No description was provided")
|
||||
|
||||
#-------------------------------------------------------------------------
|
||||
#
|
||||
@@ -71,7 +71,7 @@ class PluginManager(gen.utils.Callback):
|
||||
REPORT_MODE_CLI = 4 # Command line interface (CLI)
|
||||
|
||||
# Modes for running tools
|
||||
TOOL_MODE_GUI = 1 # Standrt tool using GUI
|
||||
TOOL_MODE_GUI = 1 # Standard tool using GUI
|
||||
TOOL_MODE_CLI = 2 # Command line interface (CLI)
|
||||
|
||||
def get_instance():
|
||||
@@ -93,8 +93,8 @@ class PluginManager(gen.utils.Callback):
|
||||
self.__report_list = []
|
||||
self.__quick_report_list = []
|
||||
self.__tool_list = []
|
||||
self.__import_list = []
|
||||
self.__export_list = []
|
||||
self.__import_plugins = []
|
||||
self.__attempt_list = []
|
||||
self.__loaddir_list = []
|
||||
self.__textdoc_list = []
|
||||
@@ -257,10 +257,6 @@ class PluginManager(gen.utils.Callback):
|
||||
""" Return the list of command line tool plugins. """
|
||||
return self.__cli_tool_list
|
||||
|
||||
def get_import_list(self):
|
||||
""" Return the list of import plugins. """
|
||||
return self.__import_list
|
||||
|
||||
def get_export_list(self):
|
||||
""" Return the list of export plugins. """
|
||||
return self.__export_list
|
||||
@@ -268,6 +264,24 @@ class PluginManager(gen.utils.Callback):
|
||||
def get_module_description(self, module):
|
||||
""" Given a module name, return the module description. """
|
||||
return self.__mod2text.get(module, '')
|
||||
|
||||
def register_plugin(self, plugin):
|
||||
"""
|
||||
@param plugin: The plugin to be registered.
|
||||
@type plugin: gen.plug.Plugin
|
||||
@return: nothing
|
||||
"""
|
||||
if isinstance(plugin, gen.plug.ImportPlugin):
|
||||
self.__import_plugins.append(plugin)
|
||||
self.__mod2text[plugin.get_module_name()] = plugin.get_description()
|
||||
|
||||
def get_import_plugins(self):
|
||||
"""
|
||||
Get the list of import plugins.
|
||||
|
||||
@return: [gen.plug.ImportPlugin] (a list of ImportPlugin instances)
|
||||
"""
|
||||
return self.__import_plugins
|
||||
|
||||
def register_export(self, export_data, title, description='', config=None,
|
||||
filename=''):
|
||||
@@ -287,21 +301,6 @@ class PluginManager(gen.utils.Callback):
|
||||
(export_data, title, description, config, filename))
|
||||
self.__mod2text[export_data.__module__] = description
|
||||
|
||||
def register_import(self, task, ffilter, mime=None, native_format=0,
|
||||
format_name=""):
|
||||
"""Register an import filter, taking the task and file filter"""
|
||||
if mime:
|
||||
del_index = -1
|
||||
for i in range(0, len(self.__import_list)):
|
||||
if self.__import_list[i][2] == mime:
|
||||
del_index = i
|
||||
if del_index != -1:
|
||||
del self.__import_list[del_index]
|
||||
|
||||
self.__import_list.append(
|
||||
(task, ffilter, mime, native_format, format_name))
|
||||
self.__mod2text[task.__module__] = format_name
|
||||
|
||||
def register_tool(self, name, category, tool_class, options_class,
|
||||
modes, translated_name, status=_("Unknown"),
|
||||
description=_UNAVAILABLE, author_name=_("Unknown"),
|
||||
@@ -548,8 +547,8 @@ class PluginManager(gen.utils.Callback):
|
||||
|
||||
self.__export_list[:] = [ item for item in self.__export_list
|
||||
if item[0].__module__ not in failed_module_names ][:]
|
||||
self.__import_list[:] = [ item for item in self.__import_list
|
||||
if item[0].__module__ 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 ][:]
|
||||
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
|
||||
|
67
src/gen/plug/_plugin.py
Normal file
67
src/gen/plug/_plugin.py
Normal file
@@ -0,0 +1,67 @@
|
||||
#
|
||||
# Gramps - a GTK+/GNOME based genealogy program
|
||||
#
|
||||
# Copyright (C) 2008 Brian G. Matherly
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
# $Id$
|
||||
|
||||
"""
|
||||
This module provides the base class for plugins.
|
||||
"""
|
||||
|
||||
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):
|
||||
"""
|
||||
@param name: A friendly name to call this plugin.
|
||||
Example: "GEDCOM Import"
|
||||
@type name: string
|
||||
@param description: An short description of the plugin.
|
||||
Example: "This plugin will import a GEDCOM file into a database"
|
||||
@type description: string
|
||||
@return: nothing
|
||||
"""
|
||||
self.__name = name
|
||||
self.__desc = description
|
||||
|
||||
def get_name(self):
|
||||
"""
|
||||
Get the name of this plugin.
|
||||
|
||||
@return: a string representing the name of the plugin
|
||||
"""
|
||||
return self.__name
|
||||
|
||||
def get_description(self):
|
||||
"""
|
||||
Get the description of this plugin.
|
||||
|
||||
@return: a string that describes the plugin
|
||||
"""
|
||||
return self.__desc
|
||||
|
||||
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
|
||||
"""
|
||||
raise NotImplementedError
|
||||
|
Reference in New Issue
Block a user