This commit is contained in:
2026-06-16 16:09:42 +08:00
commit bffb0cb6b7
644 changed files with 86620 additions and 0 deletions

41
lib/utils/helpers.py Normal file
View File

@@ -0,0 +1,41 @@
# 工具函数
import os
import subprocess
from lib.constants.config import ERROR_MESSAGES
def DetectFileType(FilePath):
"""检测文件类型"""
_, ext = os.path.splitext(FilePath)
return ext.lower()
def ExecuteCommand(command, shell=True, CaptureOutput=True, text=True):
"""执行命令"""
try:
result = subprocess.run(
command,
shell=shell,
check=True,
capture_output=CaptureOutput,
text=text
)
return result
except subprocess.CalledProcessError as e:
print(f'{ERROR_MESSAGES["COMPILE_FAILED"]}: {e}')
if e.stderr:
print(f'Error output: {e.stderr}')
return None
def AppendFileContent(FilePath, content):
"""追加文件内容"""
try:
with open(FilePath, 'a', encoding='utf-8') as f:
f.write(content)
f.write('\n')
return True
except Exception as e:
print(f'Failed to append to file {FilePath}: {e}')
return False