Allow GENERAL plugins to have category, and more flexibility

svn: r15699
This commit is contained in:
Doug Blank 2010-08-10 13:14:09 +00:00
parent aca9b9cb5c
commit f55cd42926
3 changed files with 24 additions and 16 deletions

View File

@ -175,10 +175,11 @@ class BasePluginManager(object):
# results in success. Then reload reveals the actual error.
# Looks like a bug in Python.
_module = self.reload(_module, pdata)
self.__success_list.append((filename, _module, pdata))
self.__modules[filename] = _module
self.__loaded_plugins[pdata.id] = _module
self.__mod2text[_module.__name__] = pdata.description
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
return _module
except:
import traceback
@ -192,14 +193,18 @@ class BasePluginManager(object):
Rather than just __import__(id), this will add the pdata.fpath
to sys.path first (if needed), import, and then reset path.
"""
module = None
if isinstance(pdata, basestring):
pdata = self.get_plugin(pdata)
if not pdata:
return None
if pdata.fpath not in sys.path:
sys.path.insert(0, pdata.fpath)
module = __import__(pdata.mod_name)
sys.path.pop(0)
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"
else:
module = __import__(pdata.mod_name)
return module

View File

@ -360,8 +360,9 @@ class PluginData(object):
self._reportclass = None
self._require_active = True
self._report_modes = [REPORT_MODE_GUI]
#REPORT and TOOL attr
#REPORT and TOOL and GENERAL attr
self._category = None
#REPORT and TOOL attr
self._optionclass = None
#TOOL attr
self._toolclass = None
@ -597,12 +598,11 @@ class PluginData(object):
def _get_report_modes(self):
return self._report_modes
#REPORT OR TOOL OR QUICKREPORT attributes
#REPORT or TOOL or QUICKREPORT or GENERAL attributes
def _set_category(self, category):
if not (self._ptype == REPORT or self._ptype == TOOL or
self._ptype == QUICKREPORT or self._ptype == VIEW):
if self._ptype not in [REPORT, TOOL, QUICKREPORT, VIEW, GENERAL]:
raise ValueError, 'category may only be set for ' \
'REPORT/TOOL/QUICKREPORT/VIEW plugins'
'REPORT/TOOL/QUICKREPORT/VIEW/GENERAL plugins'
self._category = category
def _get_category(self):
@ -959,7 +959,7 @@ def make_environment(**kwargs):
'GRAMPSVERSION': GRAMPSVERSION,
'START': START,
'END': END,
'IMAGE_DIR': IMAGE_DIR
'IMAGE_DIR': IMAGE_DIR,
}
env.update(kwargs)
return env
@ -1062,6 +1062,8 @@ class PluginRegister(object):
and not __debug__:
rmlist.append(ind)
continue
if plugin.fname is None:
continue
match = pymod.match(plugin.fname)
if not match:
rmlist.append(ind)

View File

@ -832,9 +832,10 @@ Location: %(fpath)s
return
id = model.get_value(node, id_col)
pdata = self.__preg.get_plugin(id)
open_file_with_default_application(
os.path.join(pdata.fpath, pdata.fname)
)
if pdata.fpath and pdata.fname:
open_file_with_default_application(
os.path.join(pdata.fpath, pdata.fname)
)
#-------------------------------------------------------------------------
#