mirror of
ssh://git.janware.com/janware/proj/jw-pkg
synced 2026-04-24 09:13:37 +02:00
lib.CopyContext: Add module
Add a CopyContext class. At this point it mostly acts as a context manager for two FileContext instances, and copying data is the canonical case to use it, hence the name. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
4c81647bbe
commit
d82bc20663
1 changed files with 41 additions and 0 deletions
41
src/python/jw/pkg/lib/CopyContext.py
Normal file
41
src/python/jw/pkg/lib/CopyContext.py
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from typing import Self
|
||||
|
||||
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
|
||||
self.__chroot = chroot
|
||||
|
||||
async def __aenter__(self) -> Self:
|
||||
self.__src = FileContext.create(self.__src_uri, chroot=self.__chroot)
|
||||
await self.__src.open()
|
||||
self.__dst = FileContext.create(self.__dst_uri, chroot=self.__chroot)
|
||||
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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue