From b6fb46b760b905ddbd5c800e965309dc931b78e9 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Thu, 14 May 2015 22:52:57 -0400 Subject: [PATCH] Database plugin type support reset_system, to reset modules --- gramps/gen/dbstate.py | 20 +++++++++----------- gramps/gen/plug/_pluginreg.py | 13 +++++++++++++ gramps/plugins/database/djangodb.gpr.py | 1 + 3 files changed, 23 insertions(+), 11 deletions(-) diff --git a/gramps/gen/dbstate.py b/gramps/gen/dbstate.py index 069934a13..0d9c30d4a 100644 --- a/gramps/gen/dbstate.py +++ b/gramps/gen/dbstate.py @@ -140,18 +140,16 @@ class DbState(Callback): pmgr.reg_plugins(USER_PLUGINS, self, None, load_on_reg=True) pdata = pmgr.get_plugin(id) - ### FIXME: Currently Django needs to reset modules - if pdata.id == "djangodb": - if self.modules_is_set(): - self.reset_modules() - else: - self.save_modules() + if pdata: + if pdata.reset_system: + if self.modules_is_set(): + self.reset_modules() + else: + self.save_modules() + mod = pmgr.load_plugin(pdata) + database = getattr(mod, pdata.databaseclass) + return database() - mod = pmgr.load_plugin(pdata) - database = getattr(mod, pdata.databaseclass) - return database() - - ## FIXME: ## Work-around for databases that need sys refresh (django): def modules_is_set(self): if hasattr(self, "_modules"): diff --git a/gramps/gen/plug/_pluginreg.py b/gramps/gen/plug/_pluginreg.py index 5619f18ed..70a93f0f2 100644 --- a/gramps/gen/plug/_pluginreg.py +++ b/gramps/gen/plug/_pluginreg.py @@ -356,6 +356,9 @@ class PluginData(object): .. attribute:: databaseclass The class in the module that is the database class + .. attribute:: reset_system + Boolean to indicate that the system (sys.modules) should + be reset. """ def __init__(self): @@ -430,6 +433,7 @@ class PluginData(object): self._order = END #DATABASE attr self._databaseclass = None + self._reset_system = False #GENERAL attr self._data = [] self._process = None @@ -949,7 +953,16 @@ class PluginData(object): def _get_databaseclass(self): return self._databaseclass + def _set_reset_system(self, reset_system): + if not self._ptype == DATABASE: + raise ValueError('reset_system may only be set for DATABASE plugins') + self._reset_system = reset_system + + def _get_reset_system(self): + return self._reset_system + databaseclass = property(_get_databaseclass, _set_databaseclass) + reset_system = property(_get_reset_system, _set_reset_system) #GENERAL attr def _set_data(self, data): diff --git a/gramps/plugins/database/djangodb.gpr.py b/gramps/plugins/database/djangodb.gpr.py index 57b30f2f5..2d0d0797b 100644 --- a/gramps/plugins/database/djangodb.gpr.py +++ b/gramps/plugins/database/djangodb.gpr.py @@ -29,3 +29,4 @@ plg.status = STABLE plg.fname = 'djangodb.py' plg.ptype = DATABASE plg.databaseclass = 'DbDjango' +plg.reset_system = True