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