Convert target path from Path to str & PurePath

The target path is just read as string from the CLI now, to allow more
complex targets (such as URLs) that don't directly map to a path.

The Packer subclass now handles the conversion from that string to a
`pathlib.PurePath`, and specific subclasses & transfer classes can convert
those to a `pathlib.Path` to perform actual filesystem operations when
necessary.
This commit is contained in:
Sybren A. Stüvel
2019-02-26 16:35:08 +01:00
parent 754edd8711
commit 03fb4da583
9 changed files with 60 additions and 42 deletions
+9 -3
View File
@@ -41,11 +41,17 @@ class BlendPath(bytes):
return super().__new__(cls, path.replace(b'\\', b'/'))
@classmethod
def mkrelative(cls, asset_path: pathlib.Path, bfile_path: pathlib.Path) -> 'BlendPath':
"""Construct a BlendPath to the asset relative to the blend file."""
def mkrelative(cls, asset_path: pathlib.Path, bfile_path: pathlib.PurePath) -> 'BlendPath':
"""Construct a BlendPath to the asset relative to the blend file.
Assumes that bfile_path is absolute.
"""
from collections import deque
bdir_parts = deque(bfile_path.absolute().parent.parts)
assert bfile_path.is_absolute(), \
'BlendPath().mkrelative(bfile_path=%r) should get absolute bfile_path' % bfile_path
bdir_parts = deque(bfile_path.parent.parts)
asset_parts = deque(asset_path.absolute().parts)
# Remove matching initial parts. What is left in bdir_parts represents