keep hierarchy option

This commit is contained in:
2026-02-19 18:06:25 +01:00
parent 6af9567a44
commit cbbe8be0d8
3 changed files with 182 additions and 6 deletions
Regular → Executable
+20 -1
View File
@@ -88,6 +88,15 @@ def add_parser(subparsers):
help="Only pack assets that are referred to with a relative path (e.g. "
"starting with `//`.",
)
parser.add_argument(
"--keep-hierarchy",
default=False,
action="store_true",
help="Preserve the full filesystem directory hierarchy in the pack. "
"All files (including the blend file) are placed at their absolute "
"path structure under the target directory. Paths in blend files are "
"rewritten to relative paths within this structure.",
)
def cli_pack(args):
@@ -119,6 +128,9 @@ def create_packer(
if args.relative_only:
raise ValueError("S3 uploader does not support the --relative-only option")
if args.keep_hierarchy:
raise ValueError("S3 uploader does not support the --keep-hierarchy option")
packer = create_s3packer(bpath, ppath, pathlib.PurePosixPath(target))
elif (
@@ -137,6 +149,11 @@ def create_packer(
"Shaman uploader does not support the --relative-only option"
)
if args.keep_hierarchy:
raise ValueError(
"Shaman uploader does not support the --keep-hierarchy option"
)
packer = create_shamanpacker(bpath, ppath, target)
elif target.lower().endswith(".zip"):
@@ -146,7 +163,8 @@ def create_packer(
raise ValueError("ZIP packer does not support on-the-fly compression")
packer = zipped.ZipPacker(
bpath, ppath, target, noop=args.noop, relative_only=args.relative_only
bpath, ppath, target, noop=args.noop, relative_only=args.relative_only,
keep_hierarchy=args.keep_hierarchy,
)
else:
packer = pack.Packer(
@@ -156,6 +174,7 @@ def create_packer(
noop=args.noop,
compress=args.compress,
relative_only=args.relative_only,
keep_hierarchy=args.keep_hierarchy,
)
if args.exclude:
+16 -5
View File
@@ -103,6 +103,7 @@ class Packer:
noop=False,
compress=False,
relative_only=False,
keep_hierarchy=False,
) -> None:
self.blendfile = bfile
self.project = project
@@ -111,6 +112,7 @@ class Packer:
self.noop = noop
self.compress = compress
self.relative_only = relative_only
self.keep_hierarchy = keep_hierarchy
self._aborted = threading.Event()
self._abort_lock = threading.RLock()
self._abort_reason = ""
@@ -241,9 +243,12 @@ class Packer:
# network shares mapped to Windows drive letters back to their UNC
# notation. Only resolving one but not the other (which can happen
# with the abosolute() call above) can cause errors.
bfile_pp = self._target_path / bfile_path.relative_to(
bpathlib.make_absolute(self.project)
)
if self.keep_hierarchy:
bfile_pp = self._target_path / bpathlib.strip_root(bfile_path)
else:
bfile_pp = self._target_path / bfile_path.relative_to(
bpathlib.make_absolute(self.project)
)
self._output_path = bfile_pp
self._progress_cb.pack_start()
@@ -335,7 +340,10 @@ class Packer:
self._new_location_paths.add(asset_path)
else:
log.debug("%s can keep using %s", bfile_path, usage.asset_path)
asset_pp = self._target_path / asset_path.relative_to(self.project)
if self.keep_hierarchy:
asset_pp = self._target_path / bpathlib.strip_root(asset_path)
else:
asset_pp = self._target_path / asset_path.relative_to(self.project)
act.new_path = asset_pp
def _find_new_paths(self):
@@ -346,7 +354,10 @@ class Packer:
assert isinstance(act, AssetAction)
relpath = bpathlib.strip_root(path)
act.new_path = pathlib.Path(self._target_path, "_outside_project", relpath)
if self.keep_hierarchy:
act.new_path = pathlib.Path(self._target_path, relpath)
else:
act.new_path = pathlib.Path(self._target_path, "_outside_project", relpath)
def _group_rewrites(self) -> None:
"""For each blend file, collect which fields need rewriting.