2026-04-22 13:09:35 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
|
|
|
|
|
from typing import Self
|
|
|
|
|
|
|
|
|
|
from .FileContext import FileContext
|
|
|
|
|
|
|
|
|
|
class CopyContext:
|
|
|
|
|
|
2026-04-24 13:59:47 +02:00
|
|
|
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
|
2026-04-22 13:09:35 +02:00
|
|
|
self.__chroot = chroot
|
|
|
|
|
|
|
|
|
|
async def __aenter__(self) -> Self:
|
2026-04-24 13:59:47 +02:00
|
|
|
if self.__src is None:
|
|
|
|
|
self.__src = FileContext.create(self.__src_uri, chroot=self.__chroot)
|
2026-04-22 13:09:35 +02:00
|
|
|
await self.__src.open()
|
2026-04-24 13:59:47 +02:00
|
|
|
if self.__dst is None:
|
|
|
|
|
self.__dst = FileContext.create(self.__dst_uri, chroot=self.__chroot)
|
2026-04-22 13:09:35 +02:00
|
|
|
await self.__dst.open()
|
|
|
|
|
return self
|
|
|
|
|
|
|
|
|
|
async def __aexit__(self, exc_type, exc, tb):
|
|
|
|
|
if self.__src is not None:
|
|
|
|
|
await self.__src.close()
|
|
|
|
|
self.__src = None
|
|
|
|
|
if self.__dst is not None:
|
|
|
|
|
await self.__dst.close()
|
|
|
|
|
self.__dst = None
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def src(self) -> FileContext:
|
|
|
|
|
return self.__src
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def dst(self) -> FileContext:
|
|
|
|
|
return self.__dst
|
|
|
|
|
|
|
|
|
|
async def _run(self) -> None:
|
|
|
|
|
await self._run()
|
|
|
|
|
|
|
|
|
|
async def run(self) -> None:
|
|
|
|
|
await self._run()
|