CopyContext: Replace src_uri, dst_uri by src, dst
Allow to pass ready-made FileContext objects to CopyContext's destructor so it doesn't need to instantiate them itself. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
772512aee0
commit
f2ca32a343
4 changed files with 21 additions and 11 deletions
|
|
@ -6,15 +6,27 @@ from .FileContext import FileContext
|
|||
|
||||
class CopyContext:
|
||||
|
||||
def __init__(self, src_uri: str, dst_uri: str, chroot=False) -> None:
|
||||
self.__src_uri = src_uri
|
||||
self.__dst_uri = dst_uri
|
||||
def __init__(self, src: str|FileContext, dst: str|FileContext, chroot=False) -> None:
|
||||
if isinstance(src, FileContext):
|
||||
self.__src = src
|
||||
self.__src_uri = src.uri
|
||||
else:
|
||||
self.__src: FileContext|None = None
|
||||
self.__src_uri = src
|
||||
if isinstance(dst, FileContext):
|
||||
self.__dst = dst
|
||||
self.__dst_uri = dst.uri
|
||||
else:
|
||||
self.__dst: FileContext|None = None
|
||||
self.__dst_uri = dst
|
||||
self.__chroot = chroot
|
||||
|
||||
async def __aenter__(self) -> Self:
|
||||
self.__src = FileContext.create(self.__src_uri, chroot=self.__chroot)
|
||||
if self.__src is None:
|
||||
self.__src = FileContext.create(self.__src_uri, chroot=self.__chroot)
|
||||
await self.__src.open()
|
||||
self.__dst = FileContext.create(self.__dst_uri, chroot=self.__chroot)
|
||||
if self.__dst is None:
|
||||
self.__dst = FileContext.create(self.__dst_uri, chroot=self.__chroot)
|
||||
await self.__dst.open()
|
||||
return self
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue