make upgrade process more forgiving: don't call InitTransient on objects until everything's upgraded

This commit is contained in:
Jeremy Penner 2011-10-05 08:42:49 -04:00
parent 68133fc2e1
commit 49f5ed1309

View file

@ -113,8 +113,7 @@ class TPrs(object):
self._fWriteToPersistent = True
if self._versionCurr != self._version:
Odb.rgtprsToUpgrade.append(self)
with self.SetTransiently():
self.InitTransient()
Odb.rgtprsToInit.append(self)
def _Upgrade(self):
self.UpgradeFrom(self._versionCurr)
self._versionCurr = self._version
@ -128,6 +127,7 @@ class Odb(object):
@classmethod
def Load(cls, fn):
cls.rgtprsToUpgrade = []
cls.rgtprsToInit = []
try:
with open(fn, "r") as fl:
tprs = cPickle.load(fl)
@ -135,13 +135,17 @@ class Odb(object):
print "error unpickling:", e
traceback.print_exc()
return None
if len(cls.rgtprsToUpgrade) > 0:
for tprsToUpgrade in cls.rgtprsToUpgrade:
tprsToUpgrade._Upgrade()
for tprsToInit in cls.rgtprsToInit:
with tprsToInit.SetTransiently():
tprsToInit.InitTransient()
if len(cls.rgtprsToUpgrade) > 0:
fnUpgraded = fn + ".upgraded"
Odb.Save(tprs, fnUpgraded)
tprs = Odb.Load(fnUpgraded)
cls.rgtprsToUpgrade = None
cls.rgtprsToInit = None
return tprs
clsList = list