DjangoDb: force load when write_version/create to make work with reset modules

This commit is contained in:
Doug Blank 2015-05-16 01:40:05 -04:00
parent cfb33ec1a2
commit 4805c3c7f0
2 changed files with 9 additions and 3 deletions

View File

@ -160,7 +160,7 @@ class DbState(Callback):
## Work-around for databases that need sys refresh (django):
def modules_is_set(self):
LOG.warn("modules_is_set?")
LOG.info("modules_is_set?")
if hasattr(self, "_modules"):
return self._modules != None
else:
@ -168,7 +168,7 @@ class DbState(Callback):
return False
def reset_modules(self):
LOG.warn("reset_modules!")
LOG.info("reset_modules!")
# First, clear out old modules:
for key in list(sys.modules.keys()):
del(sys.modules[key])
@ -177,6 +177,6 @@ class DbState(Callback):
sys.modules[key] = self._modules[key]
def save_modules(self):
LOG.warn("save_modules!")
LOG.info("save_modules!")
self._modules = sys.modules.copy()

View File

@ -362,6 +362,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
force_bsddb_upgrade=False,
force_bsddb_downgrade=False,
force_python_upgrade=False):
_LOG.info("Django loading...")
self._directory = directory
self.full_name = os.path.abspath(self._directory)
self.path = self.full_name
@ -380,9 +381,11 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
def __getattr__(self, item):
return self.dictionary[item]
_LOG.info("Django loading defaults from: " + directory)
try:
settings.configure(Module(default_settings))
except RuntimeError:
_LOG.info("Django already configured error! Shouldn't happen!")
# already configured; ignore
pass
@ -455,6 +458,7 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
self.url_types = set()
self.media_attributes = set()
self.place_types = set()
_LOG.info("Django loading... done!")
def prepare_import(self):
"""
@ -2108,6 +2112,8 @@ class DbDjango(DbWriteBase, DbReadBase, UpdateCallback, Callback):
for filename in os.listdir(defaults):
fullpath = os.path.abspath(os.path.join(defaults, filename))
shutil.copy2(fullpath, directory)
# force load, to get all modules loaded because of reset issue
self.load(directory)
def report_bm_change(self):
"""