Database plugin type support reset_system, to reset modules

This commit is contained in:
Doug Blank 2015-05-14 22:52:57 -04:00
parent 331a947ea4
commit 11ac0f1551
3 changed files with 23 additions and 11 deletions

View File

@ -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"):

View File

@ -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):

View File

@ -29,3 +29,4 @@ plg.status = STABLE
plg.fname = 'djangodb.py'
plg.ptype = DATABASE
plg.databaseclass = 'DbDjango'
plg.reset_system = True