WIP VFileSystem
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
from abc import ABC, abstractmethod
|
||||
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
|
||||
@@ -10,3 +13,53 @@ class Storage(ABC):
|
||||
@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 """
|
||||
...
|
||||
|
||||
Reference in New Issue
Block a user