Cache open blend files

This simplifies blend file handling, ensuring that blend files are only
opened once. Otherwise it would be harder to handle things like dependency
diamonds (libraries that are referenced via multiple paths through multiple
other libraries).
This commit is contained in:
Sybren A. Stüvel
2018-03-07 17:13:47 +01:00
parent c5a02423cb
commit 09a0866c14
3 changed files with 31 additions and 6 deletions
+3 -3
View File
@@ -23,9 +23,9 @@ def deps(bfilepath: pathlib.Path) -> typing.Iterator[result.BlockUsage]:
:param bfilepath: File to open.
"""
with blendfile.BlendFile(bfilepath) as bfile:
for block in asset_holding_blocks(file2blocks.iter_blocks(bfile)):
yield from blocks2assets.iter_assets(block)
bfile = blendfile.open_cached(bfilepath)
for block in asset_holding_blocks(file2blocks.iter_blocks(bfile)):
yield from blocks2assets.iter_assets(block)
def asset_holding_blocks(blocks: typing.Iterable[blendfile.BlendFileBlock]) \
+2 -3
View File
@@ -86,9 +86,8 @@ class _BlockIterator:
continue
log.debug('Expanding %d blocks in %s', len(idblocks), lib_path)
with blendfile.BlendFile(lib_path) as libfile:
yield from self.iter_blocks(libfile, idblocks)
libfile = blendfile.open_cached(lib_path)
yield from self.iter_blocks(libfile, idblocks)
def _queue_all_blocks(self, bfile: blendfile.BlendFile):
log.debug('Queueing all blocks from file %s', bfile.filepath)