Report missing files in Packer.strategise()
This commit is contained in:
parent
575a0921c1
commit
c9664ca045
@ -71,6 +71,7 @@ class Packer:
|
|||||||
# Filled by strategise()
|
# Filled by strategise()
|
||||||
self._actions = collections.defaultdict(AssetAction) \
|
self._actions = collections.defaultdict(AssetAction) \
|
||||||
# type: typing.DefaultDict[pathlib.Path, AssetAction]
|
# type: typing.DefaultDict[pathlib.Path, AssetAction]
|
||||||
|
self.missing_files = set() # type: typing.Set[pathlib.Path]
|
||||||
|
|
||||||
# Number of files we would copy, if not for --noop
|
# Number of files we would copy, if not for --noop
|
||||||
self._file_count = 0
|
self._file_count = 0
|
||||||
@ -105,6 +106,11 @@ class Packer:
|
|||||||
# blendfile thing, since different blendfiles can refer to it in
|
# blendfile thing, since different blendfiles can refer to it in
|
||||||
# different ways (for example with relative and absolute paths).
|
# different ways (for example with relative and absolute paths).
|
||||||
asset_path = usage.abspath
|
asset_path = usage.abspath
|
||||||
|
if not asset_path.exists():
|
||||||
|
log.info('Missing file: %s', asset_path)
|
||||||
|
self.missing_files.add(asset_path)
|
||||||
|
continue
|
||||||
|
|
||||||
bfile_path = usage.block.bfile.filepath.absolute()
|
bfile_path = usage.block.bfile.filepath.absolute()
|
||||||
|
|
||||||
path_in_project = self._path_in_project(asset_path)
|
path_in_project = self._path_in_project(asset_path)
|
||||||
|
|||||||
@ -122,10 +122,18 @@ class BlockUsage:
|
|||||||
log.warning('Path %s does not exist for %s', path, self)
|
log.warning('Path %s does not exist for %s', path, self)
|
||||||
|
|
||||||
def __fspath__(self) -> pathlib.Path:
|
def __fspath__(self) -> pathlib.Path:
|
||||||
"""Determine the absolute path of the asset on the filesystem."""
|
"""Determine the absolute path of the asset on the filesystem.
|
||||||
|
|
||||||
|
The path is resolved (see pathlib.Path.resolve()) if it exists on the
|
||||||
|
filesystem.
|
||||||
|
"""
|
||||||
if self._abspath is None:
|
if self._abspath is None:
|
||||||
bpath = self.block.bfile.abspath(self.asset_path)
|
bpath = self.block.bfile.abspath(self.asset_path)
|
||||||
self._abspath = bpath.to_path().resolve()
|
as_path = bpath.to_path()
|
||||||
|
try:
|
||||||
|
self._abspath = as_path.resolve()
|
||||||
|
except FileNotFoundError:
|
||||||
|
self._abspath = as_path
|
||||||
return self._abspath
|
return self._abspath
|
||||||
|
|
||||||
abspath = property(__fspath__)
|
abspath = property(__fspath__)
|
||||||
|
|||||||
BIN
tests/blendfiles/missing_textures.blend
Normal file
BIN
tests/blendfiles/missing_textures.blend
Normal file
Binary file not shown.
@ -173,3 +173,14 @@ class PackTest(AbstractPackTest):
|
|||||||
self.assertEqual(b'//../linked_cube.blend', libs[0][b'name'])
|
self.assertEqual(b'//../linked_cube.blend', libs[0][b'name'])
|
||||||
self.assertEqual(b'LILib.002', libs[1].id_name)
|
self.assertEqual(b'LILib.002', libs[1].id_name)
|
||||||
self.assertEqual(b'//../material_textures.blend', libs[1][b'name'])
|
self.assertEqual(b'//../material_textures.blend', libs[1][b'name'])
|
||||||
|
|
||||||
|
def test_missing_files(self):
|
||||||
|
infile = self.blendfiles / 'missing_textures.blend'
|
||||||
|
packer = pack.Packer(infile, self.blendfiles, self.tpath)
|
||||||
|
packer.strategise()
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
[self.blendfiles / 'textures/HDRI/Myanmar/Golden Palace 2, Old Bagan-1k.exr',
|
||||||
|
self.blendfiles / 'textures/Textures/Marble/marble_decoration-color.png'],
|
||||||
|
sorted(packer.missing_files)
|
||||||
|
)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user