From 6b51183095a3eaf102413a39f685d7c424a5f6d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Wed, 14 Mar 2018 15:19:35 +0100 Subject: [PATCH] Packer: store the output path of the blend file in the target directory This allows the Flamenco Add-on to get the final path of the blend file. --- blender_asset_tracer/pack/__init__.py | 7 +++++++ tests/test_pack.py | 10 ++++++++++ 2 files changed, 17 insertions(+) diff --git a/blender_asset_tracer/pack/__init__.py b/blender_asset_tracer/pack/__init__.py index cc3f288..03ffa05 100644 --- a/blender_asset_tracer/pack/__init__.py +++ b/blender_asset_tracer/pack/__init__.py @@ -74,6 +74,7 @@ class Packer: self._actions = collections.defaultdict(AssetAction) \ # type: typing.DefaultDict[pathlib.Path, AssetAction] self.missing_files = set() # type: typing.Set[pathlib.Path] + self._output_path = None # type: pathlib.Path # Number of files we would copy, if not for --noop self._file_count = 0 @@ -91,6 +92,11 @@ class Packer: def __exit__(self, exc_type, exc_val, exc_tb) -> None: self.close() + @property + def output_path(self) -> pathlib.Path: + """The path of the packed blend file in the target directory.""" + return self._output_path + def exclude(self, *globs: str): """Register glob-compatible patterns of files that should be ignored.""" self._exclude_globs.update(globs) @@ -107,6 +113,7 @@ class Packer: # we have to explicitly add it to the _packed_paths. bfile_path = self.blendfile.absolute() bfile_pp = self.target / bfile_path.relative_to(self.project) + self._output_path = bfile_pp act = self._actions[bfile_path] act.path_action = PathAction.KEEP_PATH diff --git a/tests/test_pack.py b/tests/test_pack.py index a24be52..5c4dbbd 100644 --- a/tests/test_pack.py +++ b/tests/test_pack.py @@ -239,3 +239,13 @@ class PackTest(AbstractPackTest): [self.blendfiles / 'textures/HDRI/Myanmar/Golden Palace 2, Old Bagan-1k.exr'], list(packer.missing_files) ) + + def test_output_path(self): + infile = self.blendfiles / 'basic_file.blend' + packer = pack.Packer(infile, self.blendfiles.parent, self.tpath) + packer.strategise() + + self.assertEqual( + self.tpath / self.blendfiles.name / infile.name, + packer.output_path + )