feat: add schema and table listing
This commit is contained in:
0
dashboard/libs/__init__.py
Normal file
0
dashboard/libs/__init__.py
Normal file
35
dashboard/libs/fs_schema.py
Normal file
35
dashboard/libs/fs_schema.py
Normal file
@@ -0,0 +1,35 @@
|
||||
from .schema import AbstractSchema
|
||||
from pathlib import Path
|
||||
|
||||
class FSSchema(AbstractSchema):
|
||||
def __init__(self, basepath, metadata_engine=None):
|
||||
self.basepath = basepath
|
||||
self._metadata_engine = metadata_engine
|
||||
|
||||
def ls(self, dir, only_files=True):
|
||||
dirpath = Path(dir)
|
||||
if only_files:
|
||||
return [f for f in dirpath.iterdir() if f.is_dir()]
|
||||
return [f for f in dirpath.iterdir()]
|
||||
|
||||
def tables(self, dir, only_files=True):
|
||||
dirpath = Path(dir)
|
||||
if only_files:
|
||||
return [f for f in dirpath.iterdir() if f.is_dir()]
|
||||
return [f for f in dirpath.iterdir()]
|
||||
|
||||
def info(self, path):
|
||||
path = Path(path)
|
||||
pass
|
||||
|
||||
def read(self, path):
|
||||
path = Path(path)
|
||||
pass
|
||||
|
||||
def write(self, path, content):
|
||||
path = Path(path)
|
||||
pass
|
||||
|
||||
def delete(self, path):
|
||||
path = Path(path)
|
||||
pass
|
||||
48
dashboard/libs/stage/fs_stage.py
Normal file
48
dashboard/libs/stage/fs_stage.py
Normal file
@@ -0,0 +1,48 @@
|
||||
from .stage import AbstractStage
|
||||
from pathlib import Path
|
||||
|
||||
class FSStage(AbstractStage):
|
||||
def __init__(self, basepath, metadata_engine=None):
|
||||
self.basepath = Path(basepath)
|
||||
self._metadata_engine = metadata_engine
|
||||
|
||||
def ls(self, dir, only_files=False, only_directories=False) -> list[str]:
|
||||
dirpath = Path(dir)
|
||||
|
||||
if only_files:
|
||||
return [str(f.relative_to(dirpath)) for f in dirpath.iterdir() if not f.is_dir()]
|
||||
|
||||
if only_directories:
|
||||
return [str(f.relative_to(dirpath)) for f in dirpath.iterdir() if f.is_dir()]
|
||||
|
||||
return [str(f.relative_to(dirpath)) for f in dirpath.iterdir()]
|
||||
|
||||
def schemas(self) -> list[str]:
|
||||
dirpath = self.basepath
|
||||
return self.ls(dirpath, only_directories=True)
|
||||
|
||||
def tables(self, schema:str) -> list[str]:
|
||||
dirpath = self.basepath / schema
|
||||
return self.ls(dirpath, only_files=True)
|
||||
|
||||
def build_table_path(self, table:str, schema:str):
|
||||
table_path = self.basepath
|
||||
if schema == '':
|
||||
return table_path / table
|
||||
return table_path / schema / table
|
||||
|
||||
def info(self, table:str, schema:str=''):
|
||||
table_path = self.build_table_path(table, schema)
|
||||
pass
|
||||
|
||||
def read(self, table:str, schema:str=''):
|
||||
table_path = self.build_table_path(table, schema)
|
||||
pass
|
||||
|
||||
def write(self, table:str, content, schema:str=''):
|
||||
table_path = self.build_table_path(table, schema)
|
||||
pass
|
||||
|
||||
def delete(self, table:str, schema:str=''):
|
||||
table_path = self.build_table_path(table, schema)
|
||||
pass
|
||||
5
dashboard/libs/stage/metadata.py
Normal file
5
dashboard/libs/stage/metadata.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from abc import ABC
|
||||
|
||||
|
||||
class AbstractMetadataEngine(ABC):
|
||||
pass
|
||||
36
dashboard/libs/stage/stage.py
Normal file
36
dashboard/libs/stage/stage.py
Normal file
@@ -0,0 +1,36 @@
|
||||
import abc
|
||||
from .metadata import AbstractMetadataEngine
|
||||
|
||||
|
||||
class AbstractStage(abc.ABC):
|
||||
metadata_engine = AbstractMetadataEngine
|
||||
|
||||
@abc.abstractmethod
|
||||
def schemas():
|
||||
""" List schemas """
|
||||
raise NotImplementedError
|
||||
|
||||
@abc.abstractmethod
|
||||
def tables(schema):
|
||||
""" List table in schema"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abc.abstractmethod
|
||||
def info(self, path):
|
||||
""" Get infos about a file"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abc.abstractmethod
|
||||
def read(self, path):
|
||||
""" Get content of a file"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abc.abstractmethod
|
||||
def write(self, path, content):
|
||||
""" Write content into the file"""
|
||||
raise NotImplementedError
|
||||
|
||||
@abc.abstractmethod
|
||||
def delete(self, path):
|
||||
""" Delete the file """
|
||||
raise NotImplementedError
|
||||
Reference in New Issue
Block a user