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
+3 -2
View File
@@ -37,7 +37,8 @@ class ZipPacker(Packer):
"""Creates a zipped BAT Pack instead of a directory."""
def _create_file_transferer(self) -> transfer.FileTransferer:
return ZipTransferrer(self.target.absolute())
target_path = pathlib.Path(self._target_path)
return ZipTransferrer(target_path.absolute())
class ZipTransferrer(transfer.FileTransferer):
@@ -61,7 +62,7 @@ class ZipTransferrer(transfer.FileTransferer):
for src, dst, act in self.iter_queue():
assert src.is_absolute(), 'expecting only absolute paths, not %r' % src
dst = dst.absolute()
dst = pathlib.Path(dst).absolute()
try:
relpath = dst.relative_to(zippath)