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:
@@ -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]) \
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user