2005-01-05 10:32:19 +05:30
|
|
|
#
|
|
|
|
# Gramps - a GTK+/GNOME based genealogy program
|
|
|
|
#
|
2005-01-09 08:58:28 +05:30
|
|
|
# Copyright (C) 2000-2005 Donald N. Allingham
|
2008-05-19 00:54:28 +05:30
|
|
|
# Copyright (C) 2008 Brian G. Matherly
|
2009-10-27 00:45:58 +05:30
|
|
|
# Copyright (C) 2009 Benny Malengier
|
2005-01-05 10:32:19 +05:30
|
|
|
#
|
|
|
|
# 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$
|
|
|
|
|
|
|
|
"""
|
2008-10-02 09:32:10 +05:30
|
|
|
The core of the GRAMPS plugin system. This module provides capability to load
|
2009-08-09 22:39:32 +05:30
|
|
|
plugins from specified directories and provide information about the loaded
|
2008-10-02 09:32:10 +05:30
|
|
|
plugins.
|
2005-01-05 10:32:19 +05:30
|
|
|
|
2008-10-02 09:32:10 +05:30
|
|
|
Plugins are divided into several categories. These are: reports, tools,
|
|
|
|
importers, exporters, quick reports, and document generators.
|
2005-01-05 10:32:19 +05:30
|
|
|
"""
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# Standard Python modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
import os
|
|
|
|
import sys
|
2005-01-09 07:48:49 +05:30
|
|
|
import re
|
2010-01-18 10:12:17 +05:30
|
|
|
from gen.ggettext import gettext as _
|
2005-01-05 10:32:19 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
|
|
|
# GRAMPS modules
|
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-12-05 12:05:21 +05:30
|
|
|
import config
|
2008-09-27 19:26:17 +05:30
|
|
|
import gen.utils
|
2009-10-24 19:23:20 +05:30
|
|
|
from gen.plug import PluginRegister
|
2005-01-05 10:32:19 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2005-12-06 12:08:09 +05:30
|
|
|
# Constants
|
2005-01-05 10:32:19 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2008-10-14 08:04:28 +05:30
|
|
|
_UNAVAILABLE = _("No description was provided")
|
2005-01-05 10:32:19 +05:30
|
|
|
|
|
|
|
#-------------------------------------------------------------------------
|
|
|
|
#
|
2009-10-25 19:22:29 +05:30
|
|
|
# BasePluginManager
|
2005-01-05 10:32:19 +05:30
|
|
|
#
|
|
|
|
#-------------------------------------------------------------------------
|
2009-10-25 19:22:29 +05:30
|
|
|
class BasePluginManager(object):
|
|
|
|
""" unique singleton storage class for a PluginManager. """
|
|
|
|
|
2008-05-19 00:54:28 +05:30
|
|
|
__instance = None
|
2008-04-01 08:42:08 +05:30
|
|
|
|
2008-05-19 00:54:28 +05:30
|
|
|
def get_instance():
|
|
|
|
""" Use this function to get the instance of the PluginManager """
|
2009-10-25 19:22:29 +05:30
|
|
|
if BasePluginManager.__instance is None:
|
|
|
|
BasePluginManager.__instance = 1 # Set to 1 for __init__()
|
|
|
|
BasePluginManager.__instance = BasePluginManager()
|
|
|
|
return BasePluginManager.__instance
|
2008-05-19 00:54:28 +05:30
|
|
|
get_instance = staticmethod(get_instance)
|
2009-10-25 19:22:29 +05:30
|
|
|
|
2008-05-19 00:54:28 +05:30
|
|
|
def __init__(self):
|
|
|
|
""" This function should only be run once by get_instance() """
|
2009-10-25 19:22:29 +05:30
|
|
|
if BasePluginManager.__instance is not 1:
|
2008-05-19 00:54:28 +05:30
|
|
|
raise Exception("This class is a singleton. "
|
|
|
|
"Use the get_instance() method")
|
2009-10-24 19:23:20 +05:30
|
|
|
|
2008-10-14 08:04:28 +05:30
|
|
|
self.__import_plugins = []
|
2008-11-04 09:42:51 +05:30
|
|
|
self.__export_plugins = []
|
2009-03-19 07:54:29 +05:30
|
|
|
self.__docgen_plugins = []
|
2009-10-24 19:23:20 +05:30
|
|
|
|
2008-05-19 00:54:28 +05:30
|
|
|
self.__attempt_list = []
|
|
|
|
self.__failmsg_list = []
|
2009-02-05 07:53:46 +05:30
|
|
|
self.__external_opt_dict = {}
|
2008-05-19 00:54:28 +05:30
|
|
|
self.__success_list = []
|
|
|
|
|
|
|
|
self.__mod2text = {}
|
2010-03-23 18:57:18 +05:30
|
|
|
self.__modules = {}
|
2008-04-01 08:42:08 +05:30
|
|
|
|
2009-10-24 19:23:20 +05:30
|
|
|
self.__pgr = PluginRegister.get_instance()
|
|
|
|
self.__registereddir_set = set()
|
|
|
|
self.__loaded_plugins = {}
|
|
|
|
|
2010-08-11 11:12:46 +05:30
|
|
|
def reg_plugins(self, direct, dbstate=None, uistate=None,
|
|
|
|
append=True, load_on_reg=False):
|
2008-05-19 00:54:28 +05:30
|
|
|
"""
|
2009-10-24 19:23:20 +05:30
|
|
|
Searches the specified directory, and registers python plugin that
|
|
|
|
are being defined in gpr.py files.
|
2008-05-19 00:54:28 +05:30
|
|
|
|
2009-10-24 19:23:20 +05:30
|
|
|
If a relationship calculator for env var LANG is present, it is
|
|
|
|
immediately loaded so it is available for all.
|
|
|
|
"""
|
2008-05-19 00:54:28 +05:30
|
|
|
# if the directory does not exist, do nothing
|
|
|
|
if not os.path.isdir(direct):
|
|
|
|
return False # return value is True for error
|
2009-01-30 07:46:00 +05:30
|
|
|
|
2009-11-06 20:44:38 +05:30
|
|
|
for (dirpath, dirnames, filenames) in os.walk(direct):
|
2009-12-17 09:32:04 +05:30
|
|
|
root, subdir = os.path.split(dirpath)
|
|
|
|
if subdir.startswith("."):
|
|
|
|
dirnames[:] = []
|
|
|
|
continue
|
2009-10-27 07:14:46 +05:30
|
|
|
for dirname in dirnames:
|
2009-11-03 07:26:27 +05:30
|
|
|
# Skip hidden and system directories:
|
|
|
|
if dirname.startswith(".") or dirname in ["po", "locale"]:
|
2009-10-27 07:14:46 +05:30
|
|
|
dirnames.remove(dirname)
|
2009-01-16 21:51:54 +05:30
|
|
|
# add the directory to the python search path
|
2010-05-02 03:00:15 +05:30
|
|
|
if append:
|
|
|
|
sys.path.append(dirpath)
|
2009-01-16 21:51:54 +05:30
|
|
|
# if the path has not already been loaded, save it in the
|
2009-10-24 19:23:20 +05:30
|
|
|
# registereddir_list list for use on reloading.
|
|
|
|
self.__registereddir_set.add(dirpath)
|
|
|
|
self.__pgr.scan_dir(dirpath)
|
2009-10-25 19:22:29 +05:30
|
|
|
|
2010-08-11 11:12:46 +05:30
|
|
|
if load_on_reg:
|
|
|
|
# Run plugins that request to be loaded on startup and
|
|
|
|
# have a load_on_reg callable.
|
|
|
|
for plugin in self.__pgr.filter_load_on_reg():
|
|
|
|
mod = self.load_plugin(plugin)
|
|
|
|
if hasattr(mod, "load_on_reg"):
|
|
|
|
try:
|
|
|
|
results = mod.load_on_reg(dbstate, uistate, plugin)
|
|
|
|
except:
|
|
|
|
import traceback
|
|
|
|
traceback.print_exc()
|
|
|
|
print "Plugin '%s' did not run; continuing..." % plugin.name
|
|
|
|
continue
|
|
|
|
try:
|
|
|
|
iter(results)
|
|
|
|
plugin.data += results
|
|
|
|
except:
|
|
|
|
plugin.data = results
|
2009-10-24 19:23:20 +05:30
|
|
|
|
2010-02-09 05:37:43 +05:30
|
|
|
def is_loaded(self, pdata_id):
|
|
|
|
"""
|
|
|
|
return True if plugin is already loaded
|
|
|
|
"""
|
|
|
|
if pdata_id in self.__loaded_plugins:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
2009-10-24 19:23:20 +05:30
|
|
|
def load_plugin(self, pdata):
|
|
|
|
"""
|
|
|
|
Load a PluginData object. This means import of the python module.
|
|
|
|
Plugin directories are added to sys path, so files are found
|
|
|
|
"""
|
|
|
|
if pdata.id in self.__loaded_plugins:
|
|
|
|
return self.__loaded_plugins[pdata.id]
|
2010-03-19 05:26:10 +05:30
|
|
|
need_reload = False
|
2009-10-24 19:23:20 +05:30
|
|
|
filename = pdata.fname
|
2010-03-23 18:57:18 +05:30
|
|
|
if filename in self.__modules:
|
|
|
|
#filename is loaded already, a different plugin in this module
|
|
|
|
_module = self.__modules[filename]
|
|
|
|
self.__success_list.append((filename, _module, pdata))
|
|
|
|
self.__loaded_plugins[pdata.id] = _module
|
|
|
|
self.__mod2text[_module.__name__] += ' - ' + pdata.description
|
|
|
|
return _module
|
2010-03-19 03:57:45 +05:30
|
|
|
if filename in self.__attempt_list:
|
2010-03-23 18:57:18 +05:30
|
|
|
#new load attempt after a fail, a reload needed
|
2010-03-19 05:26:10 +05:30
|
|
|
need_reload = True
|
2010-03-23 18:57:18 +05:30
|
|
|
#remove previous fail of the plugins in this file
|
2010-03-19 03:57:45 +05:30
|
|
|
dellist = []
|
|
|
|
for index, data in enumerate(self.__failmsg_list):
|
|
|
|
if data[0] == filename:
|
|
|
|
dellist.append(index)
|
|
|
|
dellist.reverse()
|
|
|
|
for index in dellist:
|
|
|
|
del self.__failmsg_list[index]
|
|
|
|
else:
|
|
|
|
self.__attempt_list.append(filename)
|
2009-10-24 19:23:20 +05:30
|
|
|
try:
|
2010-05-02 03:00:15 +05:30
|
|
|
_module = self.import_plugin(pdata)
|
2010-03-19 05:26:10 +05:30
|
|
|
if need_reload:
|
2010-03-19 03:57:45 +05:30
|
|
|
# For some strange reason second importing of a failed plugin
|
|
|
|
# results in success. Then reload reveals the actual error.
|
|
|
|
# Looks like a bug in Python.
|
2010-05-02 03:00:15 +05:30
|
|
|
_module = self.reload(_module, pdata)
|
2010-08-10 18:44:09 +05:30
|
|
|
if _module:
|
|
|
|
self.__success_list.append((filename, _module, pdata))
|
|
|
|
self.__modules[filename] = _module
|
|
|
|
self.__loaded_plugins[pdata.id] = _module
|
|
|
|
self.__mod2text[_module.__name__] = pdata.description
|
2009-10-24 19:23:20 +05:30
|
|
|
return _module
|
|
|
|
except:
|
2010-07-28 20:33:37 +05:30
|
|
|
import traceback
|
|
|
|
print traceback.print_exc()
|
2010-01-17 21:54:56 +05:30
|
|
|
self.__failmsg_list.append((filename, sys.exc_info(), pdata))
|
2010-03-19 03:57:45 +05:30
|
|
|
|
2009-10-24 19:23:20 +05:30
|
|
|
return None
|
2008-04-01 08:42:08 +05:30
|
|
|
|
2010-05-02 03:00:15 +05:30
|
|
|
def import_plugin(self, pdata):
|
|
|
|
"""
|
|
|
|
Rather than just __import__(id), this will add the pdata.fpath
|
|
|
|
to sys.path first (if needed), import, and then reset path.
|
|
|
|
"""
|
2010-08-10 18:44:09 +05:30
|
|
|
module = None
|
2010-05-02 03:00:15 +05:30
|
|
|
if isinstance(pdata, basestring):
|
|
|
|
pdata = self.get_plugin(pdata)
|
|
|
|
if not pdata:
|
|
|
|
return None
|
|
|
|
if pdata.fpath not in sys.path:
|
2010-08-10 18:44:09 +05:30
|
|
|
if pdata.mod_name:
|
|
|
|
sys.path.insert(0, pdata.fpath)
|
|
|
|
module = __import__(pdata.mod_name)
|
|
|
|
sys.path.pop(0)
|
|
|
|
else:
|
|
|
|
print "WARNING: module cannot be loaded"
|
2010-05-02 03:00:15 +05:30
|
|
|
else:
|
|
|
|
module = __import__(pdata.mod_name)
|
|
|
|
return module
|
|
|
|
|
2009-10-25 19:22:29 +05:30
|
|
|
def empty_managed_plugins(self):
|
|
|
|
""" For some plugins, managed Plugin are used. These are only
|
|
|
|
reobtained from the registry if this method is called
|
|
|
|
"""
|
|
|
|
# TODO: do other lists need to be reset here, too?
|
|
|
|
self.__import_plugins = []
|
|
|
|
self.__export_plugins = []
|
|
|
|
self.__docgen_plugins = []
|
|
|
|
|
2008-05-19 00:54:28 +05:30
|
|
|
def reload_plugins(self):
|
|
|
|
""" Reload previously loaded plugins """
|
|
|
|
pymod = re.compile(r"^(.*)\.py$")
|
|
|
|
|
|
|
|
oldfailmsg = self.__failmsg_list[:]
|
|
|
|
self.__failmsg_list = []
|
|
|
|
|
|
|
|
# attempt to reload all plugins that have succeeded in the past
|
2009-10-25 19:22:29 +05:30
|
|
|
self.empty_managed_plugins()
|
2010-03-23 18:57:18 +05:30
|
|
|
self.__loaded_plugins = {}
|
|
|
|
|
|
|
|
oldmodules = self.__modules
|
|
|
|
self.__modules = {}
|
2010-03-19 03:57:45 +05:30
|
|
|
dellist = []
|
2010-03-23 18:57:18 +05:30
|
|
|
#reload first modules that loaded successfully previously
|
2010-03-19 03:57:45 +05:30
|
|
|
for (index, plugin) in enumerate(self.__success_list):
|
2008-05-19 00:54:28 +05:30
|
|
|
filename = plugin[0]
|
2010-01-17 21:54:56 +05:30
|
|
|
pdata = plugin[2]
|
2008-05-19 00:54:28 +05:30
|
|
|
filename = filename.replace('pyc','py')
|
|
|
|
filename = filename.replace('pyo','py')
|
2010-03-23 18:57:18 +05:30
|
|
|
if filename in self.__modules:
|
|
|
|
#module already reloaded, a second plugin in same module
|
|
|
|
continue
|
2008-05-19 00:54:28 +05:30
|
|
|
try:
|
2010-05-02 03:00:15 +05:30
|
|
|
self.reload(plugin[1], pdata)
|
2010-03-23 18:57:18 +05:30
|
|
|
self.__modules[filename] = plugin[1]
|
|
|
|
self.__loaded_plugins[pdata.id] = plugin[1]
|
2008-05-19 00:54:28 +05:30
|
|
|
except:
|
2010-03-19 03:57:45 +05:30
|
|
|
dellist.append(index)
|
2010-01-17 21:54:56 +05:30
|
|
|
self.__failmsg_list.append((filename, sys.exc_info(), pdata))
|
2010-03-23 18:57:18 +05:30
|
|
|
|
2010-03-19 03:57:45 +05:30
|
|
|
dellist.reverse()
|
|
|
|
for index in dellist:
|
|
|
|
del self.__success_list[index]
|
2008-05-19 00:54:28 +05:30
|
|
|
|
|
|
|
# Remove previously good plugins that are now bad
|
|
|
|
# from the registered lists
|
|
|
|
self.__purge_failed()
|
|
|
|
|
|
|
|
# attempt to load the plugins that have failed in the past
|
2010-01-17 21:54:56 +05:30
|
|
|
for (filename, message, pdata) in oldfailmsg:
|
2010-03-23 18:57:18 +05:30
|
|
|
self.load_plugin(pdata)
|
2009-10-24 19:23:20 +05:30
|
|
|
|
2010-05-02 03:00:15 +05:30
|
|
|
def reload(self, module, pdata):
|
|
|
|
"""
|
2010-05-08 01:16:07 +05:30
|
|
|
Reloads modules that might not be in the path.
|
2010-05-02 03:00:15 +05:30
|
|
|
"""
|
|
|
|
try:
|
|
|
|
reload(module)
|
|
|
|
except:
|
2010-05-13 18:32:52 +05:30
|
|
|
if pdata.mod_name in sys.modules:
|
|
|
|
del sys.modules[pdata.mod_name]
|
2010-05-02 03:00:15 +05:30
|
|
|
module = self.import_plugin(pdata)
|
|
|
|
return module
|
|
|
|
|
2008-05-19 00:54:28 +05:30
|
|
|
def get_fail_list(self):
|
|
|
|
""" Return the list of failed plugins. """
|
|
|
|
return self.__failmsg_list
|
|
|
|
|
|
|
|
def get_success_list(self):
|
|
|
|
""" Return the list of succeeded plugins. """
|
|
|
|
return self.__success_list
|
2009-10-24 19:23:20 +05:30
|
|
|
|
2009-10-25 20:12:47 +05:30
|
|
|
def get_plugin(self, id):
|
|
|
|
"""
|
|
|
|
Returns a plugin object from PluginRegister by id.
|
|
|
|
"""
|
|
|
|
return self.__pgr.get_plugin(id)
|
|
|
|
|
2009-10-24 19:23:20 +05:30
|
|
|
def get_reg_reports(self, gui=True):
|
2009-10-25 19:22:29 +05:30
|
|
|
""" Return list of registered reports
|
2009-10-24 19:23:20 +05:30
|
|
|
:Param gui: bool indicating if GUI reports or CLI reports must be
|
|
|
|
returned
|
|
|
|
"""
|
2009-10-25 19:22:29 +05:30
|
|
|
return self.__pgr.report_plugins(gui)
|
2008-05-19 00:54:28 +05:30
|
|
|
|
2009-10-24 19:23:20 +05:30
|
|
|
def get_reg_tools(self, gui=True):
|
2009-10-25 19:22:29 +05:30
|
|
|
""" Return list of registered tools
|
2009-10-24 19:23:20 +05:30
|
|
|
:Param gui: bool indicating if GUI reports or CLI reports must be
|
|
|
|
returned
|
|
|
|
"""
|
2009-10-25 19:22:29 +05:30
|
|
|
return self.__pgr.tool_plugins(gui)
|
2008-05-19 00:54:28 +05:30
|
|
|
|
2009-10-24 19:23:20 +05:30
|
|
|
def get_reg_quick_reports(self):
|
2009-10-25 19:22:29 +05:30
|
|
|
""" Return list of registered quick reports
|
2009-10-24 19:23:20 +05:30
|
|
|
"""
|
2009-10-25 19:22:29 +05:30
|
|
|
return self.__pgr.quickreport_plugins()
|
2008-05-19 00:54:28 +05:30
|
|
|
|
2009-11-08 22:11:49 +05:30
|
|
|
def get_reg_views(self):
|
|
|
|
""" Return list of registered views
|
|
|
|
"""
|
|
|
|
return self.__pgr.view_plugins()
|
|
|
|
|
2009-10-24 19:23:20 +05:30
|
|
|
def get_reg_mapservices(self):
|
2009-10-25 19:22:29 +05:30
|
|
|
""" Return list of registered mapservices
|
2009-10-24 19:23:20 +05:30
|
|
|
"""
|
2009-10-25 19:22:29 +05:30
|
|
|
return self.__pgr.mapservice_plugins()
|
2009-02-03 03:25:22 +05:30
|
|
|
|
2009-10-24 19:23:20 +05:30
|
|
|
def get_reg_bookitems(self):
|
2009-10-25 19:22:29 +05:30
|
|
|
""" Return list of reports registered as bookitem
|
2009-10-24 19:23:20 +05:30
|
|
|
"""
|
2009-10-25 19:22:29 +05:30
|
|
|
return self.__pgr.bookitem_plugins()
|
2008-05-19 00:54:28 +05:30
|
|
|
|
2009-10-25 20:12:47 +05:30
|
|
|
def get_reg_gramplets(self):
|
|
|
|
""" Return list of non hidden gramplets.
|
|
|
|
"""
|
2009-10-25 21:03:50 +05:30
|
|
|
return self.__pgr.gramplet_plugins()
|
2009-10-25 20:12:47 +05:30
|
|
|
|
2010-04-04 23:46:03 +05:30
|
|
|
def get_reg_sidebars(self):
|
|
|
|
""" Return list of registered sidebars.
|
|
|
|
"""
|
|
|
|
return self.__pgr.sidebar_plugins()
|
|
|
|
|
2009-02-05 07:53:46 +05:30
|
|
|
def get_external_opt_dict(self):
|
|
|
|
""" Return the dictionary of external options. """
|
|
|
|
return self.__external_opt_dict
|
|
|
|
|
2008-05-19 00:54:28 +05:30
|
|
|
def get_module_description(self, module):
|
|
|
|
""" Given a module name, return the module description. """
|
|
|
|
return self.__mod2text.get(module, '')
|
2008-10-14 08:04:28 +05:30
|
|
|
|
2009-10-25 19:22:29 +05:30
|
|
|
def get_reg_importers(self):
|
|
|
|
""" Return list of registered importers
|
|
|
|
"""
|
|
|
|
return self.__pgr.import_plugins()
|
|
|
|
|
|
|
|
def get_reg_exporters(self):
|
|
|
|
""" Return list of registered exporters
|
|
|
|
"""
|
|
|
|
return self.__pgr.export_plugins()
|
|
|
|
|
|
|
|
def get_reg_docgens(self):
|
|
|
|
""" Return list of registered docgen
|
|
|
|
"""
|
|
|
|
return self.__pgr.docgen_plugins()
|
|
|
|
|
2010-08-11 11:12:46 +05:30
|
|
|
def get_reg_general(self, category=None):
|
|
|
|
""" Return list of registered general libs
|
|
|
|
"""
|
|
|
|
return self.__pgr.general_plugins(category)
|
|
|
|
|
|
|
|
def get_plugin_data(self, category):
|
|
|
|
"""
|
|
|
|
Gets all of the data from general plugins of type category.
|
|
|
|
plugin.data maybe a single item, an iterable, or a callable.
|
|
|
|
|
|
|
|
>>> PLUGMAN.get_plugin_data('CSS')
|
|
|
|
<a list of raw data items>
|
|
|
|
"""
|
|
|
|
retval = []
|
|
|
|
data = None
|
|
|
|
for plugin in self.__pgr.general_plugins(category):
|
2010-08-22 06:30:16 +05:30
|
|
|
data = plugin.data
|
2010-08-11 11:12:46 +05:30
|
|
|
try:
|
|
|
|
iter(data)
|
|
|
|
retval.extend(data)
|
|
|
|
except:
|
|
|
|
retval.append(data)
|
|
|
|
return retval
|
|
|
|
|
|
|
|
def process_plugin_data(self, category):
|
|
|
|
"""
|
|
|
|
Gathers all of the data from general plugins of type category,
|
|
|
|
and pass it to a single process function from one of those
|
|
|
|
plugins.
|
|
|
|
|
|
|
|
>>> PLUGMAN.process_plugin_data('CSS')
|
|
|
|
<a list of processed data items>
|
|
|
|
"""
|
|
|
|
retval = []
|
|
|
|
data = None
|
|
|
|
process = None
|
|
|
|
for plugin in self.__pgr.general_plugins(category):
|
|
|
|
if plugin.process is not None:
|
|
|
|
mod = self.load_plugin(plugin)
|
|
|
|
if hasattr(mod, plugin.process):
|
|
|
|
process = getattr(mod, plugin.process)
|
2010-08-22 06:30:16 +05:30
|
|
|
data = plugin.data
|
2010-08-11 11:12:46 +05:30
|
|
|
if data:
|
|
|
|
try:
|
|
|
|
iter(data)
|
|
|
|
retval.extend(data)
|
|
|
|
except:
|
|
|
|
retval.append(data)
|
|
|
|
if process:
|
|
|
|
return process(retval)
|
|
|
|
return retval
|
|
|
|
|
2008-10-14 08:04:28 +05:30
|
|
|
def get_import_plugins(self):
|
|
|
|
"""
|
|
|
|
Get the list of import plugins.
|
|
|
|
|
|
|
|
@return: [gen.plug.ImportPlugin] (a list of ImportPlugin instances)
|
|
|
|
"""
|
2009-10-24 19:23:20 +05:30
|
|
|
## TODO: would it not be better to remove ImportPlugin and use
|
|
|
|
## only PluginData, loading from module when importfunction needed?
|
|
|
|
if self.__import_plugins == []:
|
|
|
|
#The module still needs to be imported
|
2009-10-25 19:22:29 +05:30
|
|
|
for pdata in self.get_reg_importers():
|
2009-12-05 12:05:21 +05:30
|
|
|
if pdata.id in config.get("plugin.hiddenplugins"):
|
|
|
|
continue
|
2009-10-24 19:23:20 +05:30
|
|
|
mod = self.load_plugin(pdata)
|
|
|
|
if mod:
|
|
|
|
imp = gen.plug.ImportPlugin(name=pdata.name,
|
|
|
|
description = pdata.description,
|
2009-12-05 12:05:21 +05:30
|
|
|
import_function = getattr(mod, pdata.import_function),
|
2009-10-24 19:23:20 +05:30
|
|
|
extension = pdata.extension)
|
|
|
|
self.__import_plugins.append(imp)
|
|
|
|
|
2008-10-14 08:04:28 +05:30
|
|
|
return self.__import_plugins
|
2008-11-04 09:42:51 +05:30
|
|
|
|
|
|
|
def get_export_plugins(self):
|
|
|
|
"""
|
|
|
|
Get the list of export plugins.
|
|
|
|
|
|
|
|
@return: [gen.plug.ExportPlugin] (a list of ExportPlugin instances)
|
|
|
|
"""
|
2009-10-24 19:23:20 +05:30
|
|
|
## TODO: would it not be better to remove ExportPlugin and use
|
|
|
|
## only PluginData, loading from module when export/options needed?
|
|
|
|
if self.__export_plugins == []:
|
|
|
|
#The modules still need to be imported
|
2009-10-25 19:22:29 +05:30
|
|
|
for pdata in self.get_reg_exporters():
|
2009-12-05 12:05:21 +05:30
|
|
|
if pdata.id in config.get("plugin.hiddenplugins"):
|
|
|
|
continue
|
2009-10-24 19:23:20 +05:30
|
|
|
mod = self.load_plugin(pdata)
|
|
|
|
if mod:
|
2009-12-23 17:12:05 +05:30
|
|
|
options = None
|
|
|
|
if (pdata.export_options and
|
|
|
|
hasattr(mod, pdata.export_options)):
|
|
|
|
options = getattr(mod, pdata.export_options)
|
2010-03-21 16:03:08 +05:30
|
|
|
exp = gen.plug.ExportPlugin(name=pdata.name_accell,
|
2009-10-24 19:23:20 +05:30
|
|
|
description = pdata.description,
|
2009-12-05 12:05:21 +05:30
|
|
|
export_function = getattr(mod, pdata.export_function),
|
2009-10-24 19:23:20 +05:30
|
|
|
extension = pdata.extension,
|
2009-12-23 17:12:05 +05:30
|
|
|
config = (pdata.export_options_title, options))
|
2009-10-24 19:23:20 +05:30
|
|
|
self.__export_plugins.append(exp)
|
|
|
|
|
2008-11-04 09:42:51 +05:30
|
|
|
return self.__export_plugins
|
2009-03-19 07:54:29 +05:30
|
|
|
|
|
|
|
def get_docgen_plugins(self):
|
|
|
|
"""
|
|
|
|
Get the list of docgen plugins.
|
|
|
|
|
|
|
|
@return: [gen.plug.DocGenPlugin] (a list of DocGenPlugin instances)
|
|
|
|
"""
|
2009-10-24 19:23:20 +05:30
|
|
|
## TODO: would it not be better to return list of plugindata, and only
|
|
|
|
## import those docgen that will then actuallly be needed?
|
|
|
|
## So, only do import when docgen.get_basedoc() is requested
|
|
|
|
if self.__docgen_plugins == []:
|
|
|
|
#The modules still need to be imported
|
2009-10-25 19:22:29 +05:30
|
|
|
for pdata in self.get_reg_docgens():
|
2009-12-05 12:05:21 +05:30
|
|
|
if pdata.id in config.get("plugin.hiddenplugins"):
|
|
|
|
continue
|
2009-10-24 19:23:20 +05:30
|
|
|
mod = self.load_plugin(pdata)
|
|
|
|
if mod:
|
|
|
|
dgp = gen.plug.DocGenPlugin(name=pdata.name,
|
|
|
|
description = pdata.description,
|
2009-12-05 12:05:21 +05:30
|
|
|
basedoc = getattr(mod, pdata.basedocclass),
|
2009-10-24 19:23:20 +05:30
|
|
|
paper = pdata.paper,
|
|
|
|
style = pdata.style,
|
|
|
|
extension = pdata.extension )
|
|
|
|
self.__docgen_plugins.append(dgp)
|
|
|
|
|
2009-03-19 07:54:29 +05:30
|
|
|
return self.__docgen_plugins
|
2008-05-19 00:54:28 +05:30
|
|
|
|
2009-02-05 07:53:46 +05:30
|
|
|
def register_option(self, option, guioption):
|
|
|
|
"""
|
|
|
|
Register an external option.
|
|
|
|
|
|
|
|
Register a mapping from option to guioption for an option
|
|
|
|
that is not native to Gramps but provided by the plugin writer.
|
|
|
|
This should typically be called during initialisation of a
|
|
|
|
ReportOptions class.
|
|
|
|
@param option: the option class
|
|
|
|
@type option: class that inherits from gen.plug.menu.Option
|
|
|
|
@param guioption: the gui-option class
|
|
|
|
@type guioption: class that inherits from gtk.Widget.
|
|
|
|
"""
|
|
|
|
self.__external_opt_dict[option] = guioption;
|
|
|
|
|
2008-05-19 00:54:28 +05:30
|
|
|
def __purge_failed(self):
|
|
|
|
"""
|
|
|
|
Purge the failed plugins from the corresponding lists.
|
|
|
|
"""
|
|
|
|
failed_module_names = [
|
|
|
|
os.path.splitext(os.path.basename(filename))[0]
|
2010-01-17 21:54:56 +05:30
|
|
|
for filename, msg, pdata in self.__failmsg_list
|
2008-05-19 00:54:28 +05:30
|
|
|
]
|
2009-10-24 19:23:20 +05:30
|
|
|
|
2008-11-04 09:42:51 +05:30
|
|
|
self.__export_plugins[:] = [ item for item in self.__export_plugins
|
2009-01-30 07:46:00 +05:30
|
|
|
if item.get_module_name() not in failed_module_names ][:]
|
2008-10-14 08:04:28 +05:30
|
|
|
self.__import_plugins[:] = [ item for item in self.__import_plugins
|
2009-01-30 07:46:00 +05:30
|
|
|
if item.get_module_name() not in failed_module_names ][:]
|
2009-03-19 07:54:29 +05:30
|
|
|
self.__docgen_plugins[:] = [ item for item in self.__docgen_plugins
|
|
|
|
if item.get_module_name() not in failed_module_names ][:]
|