Database plugin type support reset_system, to reset modules
This commit is contained in:
parent
331a947ea4
commit
11ac0f1551
@ -140,18 +140,16 @@ class DbState(Callback):
|
|||||||
pmgr.reg_plugins(USER_PLUGINS, self, None, load_on_reg=True)
|
pmgr.reg_plugins(USER_PLUGINS, self, None, load_on_reg=True)
|
||||||
pdata = pmgr.get_plugin(id)
|
pdata = pmgr.get_plugin(id)
|
||||||
|
|
||||||
### FIXME: Currently Django needs to reset modules
|
if pdata:
|
||||||
if pdata.id == "djangodb":
|
if pdata.reset_system:
|
||||||
if self.modules_is_set():
|
if self.modules_is_set():
|
||||||
self.reset_modules()
|
self.reset_modules()
|
||||||
else:
|
else:
|
||||||
self.save_modules()
|
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):
|
## Work-around for databases that need sys refresh (django):
|
||||||
def modules_is_set(self):
|
def modules_is_set(self):
|
||||||
if hasattr(self, "_modules"):
|
if hasattr(self, "_modules"):
|
||||||
|
@ -356,6 +356,9 @@ class PluginData(object):
|
|||||||
|
|
||||||
.. attribute:: databaseclass
|
.. attribute:: databaseclass
|
||||||
The class in the module that is the database class
|
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):
|
def __init__(self):
|
||||||
@ -430,6 +433,7 @@ class PluginData(object):
|
|||||||
self._order = END
|
self._order = END
|
||||||
#DATABASE attr
|
#DATABASE attr
|
||||||
self._databaseclass = None
|
self._databaseclass = None
|
||||||
|
self._reset_system = False
|
||||||
#GENERAL attr
|
#GENERAL attr
|
||||||
self._data = []
|
self._data = []
|
||||||
self._process = None
|
self._process = None
|
||||||
@ -949,7 +953,16 @@ class PluginData(object):
|
|||||||
def _get_databaseclass(self):
|
def _get_databaseclass(self):
|
||||||
return self._databaseclass
|
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)
|
databaseclass = property(_get_databaseclass, _set_databaseclass)
|
||||||
|
reset_system = property(_get_reset_system, _set_reset_system)
|
||||||
|
|
||||||
#GENERAL attr
|
#GENERAL attr
|
||||||
def _set_data(self, data):
|
def _set_data(self, data):
|
||||||
|
@ -29,3 +29,4 @@ plg.status = STABLE
|
|||||||
plg.fname = 'djangodb.py'
|
plg.fname = 'djangodb.py'
|
||||||
plg.ptype = DATABASE
|
plg.ptype = DATABASE
|
||||||
plg.databaseclass = 'DbDjango'
|
plg.databaseclass = 'DbDjango'
|
||||||
|
plg.reset_system = True
|
||||||
|
Loading…
Reference in New Issue
Block a user