Path rewriting for sequences seems to be working too.
This commit is contained in:
parent
71dd5bc11b
commit
e2123f8090
@ -173,10 +173,23 @@ class Packer:
|
|||||||
|
|
||||||
# Find the same block in the newly copied file.
|
# Find the same block in the newly copied file.
|
||||||
block = bfile.dereference_pointer(usage.block.addr_old)
|
block = bfile.dereference_pointer(usage.block.addr_old)
|
||||||
log.info(' - updating field %s of block %s',
|
if usage.path_full_field is None:
|
||||||
usage.path_full_field.name.name_only, block)
|
log.info(' - updating field %s of block %s',
|
||||||
written = block.set(usage.path_full_field.name.name_only, relpath)
|
usage.path_dir_field.name.name_only, block)
|
||||||
log.info(' - written %d bytes', written)
|
reldir = bpathlib.BlendPath.mkrelative(asset_pp.parent, bfile_pp)
|
||||||
|
written = block.set(usage.path_dir_field.name.name_only, reldir)
|
||||||
|
log.info(' - written %d bytes', written)
|
||||||
|
|
||||||
|
# BIG FAT ASSUMPTION that the filename (e.g. basename
|
||||||
|
# without path) does not change. This makes things much
|
||||||
|
# easier, as in the sequence editor the directory and
|
||||||
|
# filename fields are in different blocks. See the
|
||||||
|
# blocks2assets.scene() function for the implementation.
|
||||||
|
else:
|
||||||
|
log.info(' - updating field %s of block %s',
|
||||||
|
usage.path_full_field.name.name_only, block)
|
||||||
|
written = block.set(usage.path_full_field.name.name_only, relpath)
|
||||||
|
log.info(' - written %d bytes', written)
|
||||||
bfile.fileobj.flush()
|
bfile.fileobj.flush()
|
||||||
|
|
||||||
def _copy_asset_and_deps(self, asset_path: pathlib.Path, action: AssetAction):
|
def _copy_asset_and_deps(self, asset_path: pathlib.Path, action: AssetAction):
|
||||||
@ -188,9 +201,19 @@ class Packer:
|
|||||||
|
|
||||||
# Copy its dependencies.
|
# Copy its dependencies.
|
||||||
for usage in action.usages:
|
for usage in action.usages:
|
||||||
|
if not usage.is_sequence:
|
||||||
|
self._copy_to_target(usage.abspath, packed_path)
|
||||||
|
continue
|
||||||
|
|
||||||
|
first_pp = self._packed_paths[usage.abspath]
|
||||||
|
|
||||||
|
# In case of globbing, we only support globbing by filename,
|
||||||
|
# and not by directory.
|
||||||
|
assert '*' not in str(first_pp) or '*' in first_pp.name
|
||||||
|
|
||||||
|
packed_base_dir = first_pp.parent
|
||||||
for file_path in usage.files():
|
for file_path in usage.files():
|
||||||
# TODO(Sybren): handle sequences properly!
|
packed_path = packed_base_dir / file_path.name
|
||||||
packed_path = self._packed_paths[file_path]
|
|
||||||
self._copy_to_target(file_path, packed_path)
|
self._copy_to_target(file_path, packed_path)
|
||||||
|
|
||||||
def _copy_to_target(self, asset_path: pathlib.Path, target: pathlib.Path):
|
def _copy_to_target(self, asset_path: pathlib.Path, target: pathlib.Path):
|
||||||
|
|||||||
@ -156,7 +156,7 @@ def scene(block: blendfile.BlendFileBlock) -> typing.Iterator[result.BlockUsage]
|
|||||||
asset_path = bpathlib.BlendPath(dirname) / basename
|
asset_path = bpathlib.BlendPath(dirname) / basename
|
||||||
|
|
||||||
is_sequence = seq_type not in single_asset_types
|
is_sequence = seq_type not in single_asset_types
|
||||||
yield result.BlockUsage(seq, asset_path,
|
yield result.BlockUsage(seq_strip, asset_path,
|
||||||
is_sequence=is_sequence,
|
is_sequence=is_sequence,
|
||||||
path_dir_field=dn_field,
|
path_dir_field=dn_field,
|
||||||
path_base_field=bn_field)
|
path_base_field=bn_field)
|
||||||
|
|||||||
@ -16,8 +16,8 @@ class DoesNotExist(OSError):
|
|||||||
def expand_sequence(path: pathlib.Path) -> typing.Iterator[pathlib.Path]:
|
def expand_sequence(path: pathlib.Path) -> typing.Iterator[pathlib.Path]:
|
||||||
"""Expand a file sequence path into the actual file paths.
|
"""Expand a file sequence path into the actual file paths.
|
||||||
|
|
||||||
:param path: can be either a glob pattern (must contain a * character),
|
:param path: can be either a glob pattern (must contain a * character)
|
||||||
a directory, or the path of the first file in the sequence.
|
or the path of the first file in the sequence.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
if '*' in str(path): # assume it is a glob
|
if '*' in str(path): # assume it is a glob
|
||||||
@ -31,9 +31,7 @@ def expand_sequence(path: pathlib.Path) -> typing.Iterator[pathlib.Path]:
|
|||||||
raise DoesNotExist(path)
|
raise DoesNotExist(path)
|
||||||
|
|
||||||
if path.is_dir():
|
if path.is_dir():
|
||||||
log.debug('expanding directory %s', path)
|
raise TypeError('path is a directory: %s' % path)
|
||||||
yield from sorted(path.rglob('*'))
|
|
||||||
return
|
|
||||||
|
|
||||||
log.debug('expanding file sequence %s', path)
|
log.debug('expanding file sequence %s', path)
|
||||||
|
|
||||||
|
|||||||
@ -16,8 +16,8 @@ class BlockUsage:
|
|||||||
name of the block.
|
name of the block.
|
||||||
:ivar block:
|
:ivar block:
|
||||||
:ivar asset_path: The path of the asset, if is_sequence=False. Otherwise
|
:ivar asset_path: The path of the asset, if is_sequence=False. Otherwise
|
||||||
it can be either a glob pattern (must contain a * byte), a directory,
|
it can be either a glob pattern (must contain a * byte) or the path of
|
||||||
or the path of the first file in the sequence.
|
the first file in the sequence.
|
||||||
:ivar is_sequence: Indicates whether this file is alone (False), the
|
:ivar is_sequence: Indicates whether this file is alone (False), the
|
||||||
first of a sequence (True, and the path points to a file), or a
|
first of a sequence (True, and the path points to a file), or a
|
||||||
directory containing a sequence (True, and path points to a directory).
|
directory containing a sequence (True, and path points to a directory).
|
||||||
@ -82,9 +82,15 @@ class BlockUsage:
|
|||||||
return b'-unnamed-'
|
return b'-unnamed-'
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
|
if self.path_full_field is None:
|
||||||
|
field_name = self.path_dir_field.name.name_full.decode() + \
|
||||||
|
'/' + \
|
||||||
|
self.path_base_field.name.name_full.decode()
|
||||||
|
else:
|
||||||
|
field_name = self.path_full_field.name.name_full.decode()
|
||||||
return '<BlockUsage name=%r type=%r field=%r asset=%r%s>' % (
|
return '<BlockUsage name=%r type=%r field=%r asset=%r%s>' % (
|
||||||
self.block_name, self.block.dna_type_name,
|
self.block_name, self.block.dna_type_name,
|
||||||
self.path_full_field.name.name_full.decode(), self.asset_path,
|
field_name, self.asset_path,
|
||||||
' sequence' if self.is_sequence else ''
|
' sequence' if self.is_sequence else ''
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@ -80,15 +80,15 @@ class DepsTest(AbstractTracerTest):
|
|||||||
actual = Expect(actual_type, actual_full_field, actual_dirname, actual_basename,
|
actual = Expect(actual_type, actual_full_field, actual_dirname, actual_basename,
|
||||||
dep.asset_path, dep.is_sequence)
|
dep.asset_path, dep.is_sequence)
|
||||||
|
|
||||||
exp = expects[dep.block_name]
|
exp = expects.get(dep.block_name, None)
|
||||||
if isinstance(exp, set):
|
if isinstance(exp, (set, list)):
|
||||||
self.assertIn(actual, exp, msg='for block %s' % dep.block_name)
|
self.assertIn(actual, exp, msg='for block %s' % dep.block_name)
|
||||||
exp.discard(actual)
|
exp.remove(actual)
|
||||||
if not exp:
|
if not exp:
|
||||||
# Don't leave empty sets in expects.
|
# Don't leave empty sets in expects.
|
||||||
del expects[dep.block_name]
|
del expects[dep.block_name]
|
||||||
else:
|
else:
|
||||||
self.assertEqual(exp, actual, msg='for block %s' % dep.block_name)
|
self.assertEqual(actual, exp, msg='for block %s' % dep.block_name)
|
||||||
del expects[dep.block_name]
|
del expects[dep.block_name]
|
||||||
|
|
||||||
# All expected uses should have been seen.
|
# All expected uses should have been seen.
|
||||||
@ -118,16 +118,17 @@ class DepsTest(AbstractTracerTest):
|
|||||||
|
|
||||||
def test_seq_image_sequence(self):
|
def test_seq_image_sequence(self):
|
||||||
expects = {
|
expects = {
|
||||||
b'SQ000210.png': Expect(
|
b'-unnamed-': [
|
||||||
'Sequence', None, 'dir[768]', 'name[256]', b'//imgseq/000210.png', True),
|
Expect('Strip', None, 'dir[768]', 'name[256]', b'//imgseq/000210.png', True),
|
||||||
b'SQvideo-tiny.mkv': Expect(
|
|
||||||
'Sequence', None, 'dir[768]', 'name[256]',
|
|
||||||
b'//../../../../cloud/pillar/testfiles/video-tiny.mkv', False),
|
|
||||||
|
|
||||||
# The sound will be referenced twice, from the sequence strip and an SO data block.
|
# Video strip reference.
|
||||||
b'SQvideo-tiny.001': Expect(
|
Expect('Strip', None, 'dir[768]', 'name[256]',
|
||||||
'Sequence', None, 'dir[768]', 'name[256]',
|
b'//../../../../cloud/pillar/testfiles/video-tiny.mkv', False),
|
||||||
b'//../../../../cloud/pillar/testfiles/video-tiny.mkv', False),
|
|
||||||
|
# The sound will be referenced twice, from the sequence strip and an SO data block.
|
||||||
|
Expect('Strip', None, 'dir[768]', 'name[256]',
|
||||||
|
b'//../../../../cloud/pillar/testfiles/video-tiny.mkv', False),
|
||||||
|
],
|
||||||
b'SOvideo-tiny.mkv': Expect(
|
b'SOvideo-tiny.mkv': Expect(
|
||||||
'bSound', 'name[1024]', None, None,
|
'bSound', 'name[1024]', None, None,
|
||||||
b'//../../../../cloud/pillar/testfiles/video-tiny.mkv', False),
|
b'//../../../../cloud/pillar/testfiles/video-tiny.mkv', False),
|
||||||
|
|||||||
@ -14,12 +14,6 @@ class ExpandFileSequenceTest(AbstractBlendFileTest):
|
|||||||
actual = list(file_sequence.expand_sequence(path))
|
actual = list(file_sequence.expand_sequence(path))
|
||||||
self.assertEqual(self.imgseq, actual)
|
self.assertEqual(self.imgseq, actual)
|
||||||
|
|
||||||
def test_directory(self):
|
|
||||||
path = self.blendfiles / 'imgseq'
|
|
||||||
actual = list(file_sequence.expand_sequence(path))
|
|
||||||
expected = self.imgseq + [self.blendfiles / 'imgseq/LICENSE.txt']
|
|
||||||
self.assertEqual(expected, actual)
|
|
||||||
|
|
||||||
def test_first_file(self):
|
def test_first_file(self):
|
||||||
path = self.blendfiles / 'imgseq/000210.png'
|
path = self.blendfiles / 'imgseq/000210.png'
|
||||||
actual = list(file_sequence.expand_sequence(path))
|
actual = list(file_sequence.expand_sequence(path))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user