66 lines
2.0 KiB
Python
66 lines
2.0 KiB
Python
from ..config import StorageItem
|
|
from abc import ABC, abstractmethod
|
|
from pathlib import PurePosixPath, PurePath
|
|
from collections.abc import Awaitable
|
|
from inspect import isawaitable
|
|
|
|
class Storage(ABC):
|
|
@classmethod
|
|
def get_storage_type(cls) -> str:
|
|
return cls.__name__ + "Item"
|
|
|
|
@classmethod
|
|
@abstractmethod
|
|
def from_config(cls, cfg: StorageItem) -> 'Storage':
|
|
...
|
|
|
|
@classmethod
|
|
@abstractmethod
|
|
def support_random_access(cls) -> bool:
|
|
...
|
|
|
|
@abstractmethod
|
|
def listdir(self, path=PurePosixPath("")) -> list[PurePosixPath] | Awaitable[list[PurePosixPath]]:
|
|
""" list storage file in 'path' """
|
|
...
|
|
|
|
@abstractmethod
|
|
def exists(self, path: PurePosixPath) -> bool | Awaitable[bool]:
|
|
""" if the file or dir is exists """
|
|
...
|
|
|
|
@abstractmethod
|
|
def is_dir(self, path: PurePosixPath) -> bool | Awaitable[bool]:
|
|
""" if the path is dir """
|
|
...
|
|
|
|
@abstractmethod
|
|
def is_file(self, path: PurePosixPath) -> bool | Awaitable[bool]:
|
|
""" if the path is file """
|
|
...
|
|
|
|
@abstractmethod
|
|
def get_source_path(self, path: PurePosixPath) -> PurePath | Awaitable[PurePath]:
|
|
""" get the file's source path (the location when it was backuped) """
|
|
...
|
|
|
|
@abstractmethod
|
|
def get_storage_path(self, path: PurePath) -> PurePosixPath | Awaitable[PurePosixPath]:
|
|
""" get the file's storage path (the location in the storage) """
|
|
...
|
|
|
|
@abstractmethod
|
|
def backup_file(self, source: PurePath, target: PurePosixPath) -> None | Awaitable[None]:
|
|
""" copy file from local to storage """
|
|
...
|
|
|
|
@abstractmethod
|
|
def restore_file(self, source: PurePosixPath, target: PurePath) -> None | Awaitable[None]:
|
|
""" copy file from storage to local """
|
|
...
|
|
|
|
@abstractmethod
|
|
def remove(self, path: PurePosixPath) -> None | Awaitable[None]:
|
|
""" delete file or dir from storage """
|
|
...
|