|
@@ -1,34 +0,0 @@
|
|
|
-import os
|
|
|
-import re
|
|
|
-from pathlib import Path
|
|
|
-
|
|
|
-
|
|
|
-def is_prod() -> bool:
|
|
|
- """判断当前环境是否为生产环境"""
|
|
|
- return os.getenv('ENV', 'test') == 'prod'
|
|
|
-
|
|
|
-
|
|
|
-def get_root_dir() -> str:
|
|
|
- """获取项目根目录的绝对路径"""
|
|
|
- current_path = Path(__file__).resolve()
|
|
|
- root_path = current_path.parent if not current_path.is_dir() else current_path
|
|
|
- while True:
|
|
|
- if 'requirements.txt' in os.listdir(root_path):
|
|
|
- return str(root_path.absolute())
|
|
|
- root_path = root_path.parent
|
|
|
-
|
|
|
-
|
|
|
-def get_abs_path(relative_path: str) -> str:
|
|
|
- """获取目标文件或目录的相对路径在系统中的绝对路径"""
|
|
|
- return os.path.join(get_root_dir(), relative_path)
|
|
|
-
|
|
|
-
|
|
|
-def pascal_to_snake(pascal_str: str) -> str:
|
|
|
- """将Pascal字符串转为蛇形字符串"""
|
|
|
- snake_str = re.sub(r'([a-z])([A-Z])', r'\1_\2', pascal_str)
|
|
|
- return snake_str.lower()
|
|
|
-
|
|
|
-
|
|
|
-def snake_to_pascal(snake_str: str) -> str:
|
|
|
- """将蛇形字符串转为Pascal字符串"""
|
|
|
- return ''.join([item.title() for item in snake_str.split('_')])
|