Path rewriting for sequences seems to be working too.
This commit is contained in:
@@ -173,10 +173,23 @@ class Packer:
|
||||
|
||||
# Find the same block in the newly copied file.
|
||||
block = bfile.dereference_pointer(usage.block.addr_old)
|
||||
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)
|
||||
if usage.path_full_field is None:
|
||||
log.info(' - updating field %s of block %s',
|
||||
usage.path_dir_field.name.name_only, block)
|
||||
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()
|
||||
|
||||
def _copy_asset_and_deps(self, asset_path: pathlib.Path, action: AssetAction):
|
||||
@@ -188,9 +201,19 @@ class Packer:
|
||||
|
||||
# Copy its dependencies.
|
||||
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():
|
||||
# TODO(Sybren): handle sequences properly!
|
||||
packed_path = self._packed_paths[file_path]
|
||||
packed_path = packed_base_dir / file_path.name
|
||||
self._copy_to_target(file_path, packed_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
|
||||
|
||||
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,
|
||||
path_dir_field=dn_field,
|
||||
path_base_field=bn_field)
|
||||
|
||||
@@ -16,8 +16,8 @@ class DoesNotExist(OSError):
|
||||
def expand_sequence(path: pathlib.Path) -> typing.Iterator[pathlib.Path]:
|
||||
"""Expand a file sequence path into the actual file paths.
|
||||
|
||||
:param path: can be either a glob pattern (must contain a * character),
|
||||
a directory, or the path of the first file in the sequence.
|
||||
:param path: can be either a glob pattern (must contain a * character)
|
||||
or the path of the first file in the sequence.
|
||||
"""
|
||||
|
||||
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)
|
||||
|
||||
if path.is_dir():
|
||||
log.debug('expanding directory %s', path)
|
||||
yield from sorted(path.rglob('*'))
|
||||
return
|
||||
raise TypeError('path is a directory: %s' % path)
|
||||
|
||||
log.debug('expanding file sequence %s', path)
|
||||
|
||||
|
||||
@@ -16,8 +16,8 @@ class BlockUsage:
|
||||
name of the block.
|
||||
:ivar block:
|
||||
: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,
|
||||
or the path of the first file in the sequence.
|
||||
it can be either a glob pattern (must contain a * byte) or the path of
|
||||
the first file in the sequence.
|
||||
: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
|
||||
directory containing a sequence (True, and path points to a directory).
|
||||
@@ -82,9 +82,15 @@ class BlockUsage:
|
||||
return b'-unnamed-'
|
||||
|
||||
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>' % (
|
||||
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 ''
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user