chore: Add pylint for storage (#1298)

This commit is contained in:
Fangyin Cheng
2024-03-15 15:42:46 +08:00
committed by GitHub
parent a207640ff2
commit 8897d6e8fd
50 changed files with 784 additions and 667 deletions

View File

@@ -1,14 +1,21 @@
"""Database information class and database type enumeration."""
import os
from enum import Enum
from typing import Optional
class DbInfo:
"""Database information class."""
def __init__(self, name, is_file_db: bool = False):
"""Create a new instance of DbInfo."""
self.name = name
self.is_file_db = is_file_db
class DBType(Enum):
"""Database type enumeration."""
Mysql = DbInfo("mysql")
OCeanBase = DbInfo("oceanbase")
DuckDb = DbInfo("duckdb", True)
@@ -22,14 +29,24 @@ class DBType(Enum):
Doris = DbInfo("doris")
Hive = DbInfo("hive")
def value(self):
def value(self) -> str:
"""Return the name of the database type."""
return self._value_.name
def is_file_db(self):
def is_file_db(self) -> bool:
"""Return whether the database is a file database."""
return self._value_.is_file_db
@staticmethod
def of_db_type(db_type: str):
def of_db_type(db_type: str) -> Optional["DBType"]:
"""Return the database type of the given name.
Args:
db_type (str): The name of the database type.
Returns:
Optional[DBType]: The database type of the given name.
"""
for item in DBType:
if item.value() == db_type:
return item
@@ -37,7 +54,7 @@ class DBType(Enum):
@staticmethod
def parse_file_db_name_from_path(db_type: str, local_db_path: str):
"""Parse out the database name of the embedded database from the file path"""
"""Parse out the database name of the embedded database from the file path."""
base_name = os.path.basename(local_db_path)
db_name = os.path.splitext(base_name)[0]
if "." in db_name: