def __generatePackages(self, nameFormatter, env, cacheKey, sandboxEnabled):
# use separate caches with and without sandbox
if sandboxEnabled:
cacheName = ".bob-packages-sb.pickle"
else:
cacheName = ".bob-packages.pickle"
# try to load the persisted packages
states = { n:s() for (n,s) in self.__states.items() }
rootPkg = Package()
rootPkg.construct("<root>", [], nameFormatter, None, [], [], states,
{}, {}, None, None, [], {}, -1)
try:
with open(cacheName, "rb") as f:
persistedCacheKey = f.read(len(cacheKey))
if cacheKey == persistedCacheKey:
tmp = PackageUnpickler(f, self.getRecipe, self.__plugins,
nameFormatter).load()
return tmp.toStep(nameFormatter, rootPkg).getPackage()
except (EOFError, OSError, pickle.UnpicklingError):
pass
# not cached -> calculate packages
result = self.__rootRecipe.prepare(nameFormatter, env, sandboxEnabled,
states)[0]
# save package tree for next invocation
tmp = CoreStepRef(rootPkg, result.getPackageStep())
try:
newCacheName = cacheName + ".new"
with open(newCacheName, "wb") as f:
f.write(cacheKey)
PackagePickler(f, nameFormatter).dump(tmp)
os.replace(newCacheName, cacheName)
except OSError as e:
print("Error saving internal state:", str(e), file=sys.stderr)
return result
评论列表
文章目录