From cc4043969eb9bd20e8eda12ea7cf9790fb9af5fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Mon, 12 Sep 2022 14:33:43 +0200 Subject: [PATCH] Change when the `trace_blendfile()` callback is called Previously the `callback.trace_blendfile()` callback was called just before tracing its dependencies would start, i.e. after opening it. This is now changed to before opening it, because that can take a long time (to load SDNA). this will make any UI (like the Flamenco add-on) report the right filename when waiting for big files, instead of lingering on the last-opened (potentially very small) blend file. --- CHANGELOG.md | 4 ++++ blender_asset_tracer/trace/__init__.py | 4 +--- blender_asset_tracer/trace/file2blocks.py | 10 ++++++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 341fd80..3fe07b5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,10 @@ This file logs the changes that are actually interesting to users (new features, changed functionality, fixed bugs). +# Version 1.14 (in development) + +- While tracing dependencies, call the progress callback function before opening a blend file, instead of before iterating over its contents. The opening (and loading of SDNA) takes a significant amount of time, so this will make any UI (like the Flamenco add-on) report the right filename when waiting for big files. + # Version 1.13 (2022-07-14) - Improve an error message when packing fails. It now not only mentions that something went wrong, but also which file and which operation on that file (copy or move) was involved. diff --git a/blender_asset_tracer/trace/__init__.py b/blender_asset_tracer/trace/__init__.py index 7afc376..f88f5f3 100644 --- a/blender_asset_tracer/trace/__init__.py +++ b/blender_asset_tracer/trace/__init__.py @@ -49,12 +49,10 @@ def deps( :param progress_cb: Progress callback object. """ - log.info("opening: %s", bfilepath) - bfile = blendfile.open_cached(bfilepath) - bi = file2blocks.BlockIterator() if progress_cb: bi.progress_cb = progress_cb + bfile = bi.open_blendfile(bfilepath) # Remember which block usages we've reported already, without keeping the # blocks themselves in memory. diff --git a/blender_asset_tracer/trace/file2blocks.py b/blender_asset_tracer/trace/file2blocks.py index 63074d4..af5ff2e 100644 --- a/blender_asset_tracer/trace/file2blocks.py +++ b/blender_asset_tracer/trace/file2blocks.py @@ -65,6 +65,13 @@ class BlockIterator: self.progress_cb = progress.Callback() + def open_blendfile(self, bfilepath: pathlib.Path) -> blendfile.BlendFile: + """Open a blend file, sending notification about this to the progress callback.""" + + log.info("opening: %s", bfilepath) + self.progress_cb.trace_blendfile(bfilepath) + return blendfile.open_cached(bfilepath) + def iter_blocks( self, bfile: blendfile.BlendFile, @@ -72,7 +79,6 @@ class BlockIterator: ) -> typing.Iterator[blendfile.BlendFileBlock]: """Expand blocks with dependencies from other libraries.""" - self.progress_cb.trace_blendfile(bfile.filepath) log.info("inspecting: %s", bfile.filepath) if limit_to: self._queue_named_blocks(bfile, limit_to) @@ -127,7 +133,7 @@ class BlockIterator: continue log.debug("Expanding %d blocks in %s", len(idblocks), lib_path) - libfile = blendfile.open_cached(lib_path) + libfile = self.open_blendfile(lib_path) yield from self.iter_blocks(libfile, idblocks) def _queue_all_blocks(self, bfile: blendfile.BlendFile):