xiaozhi-esp32-server/main/xiaozhi-server/utils/finder.py
2026-04-16 21:08:01 +08:00

36 lines
1 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import os
from logging import getLogger
from .constant import APP_DIR
logger = getLogger(__name__)
def find_libs_dir(system: str = "", arch: str = "") -> str | None:
"""查找libs目录(用于动态库)
Args:
system: 系统名称(如Windows、Linux、Darwin)
arch: 架构名称(如x64、x86、arm64)
Returns:
找到的libs目录绝对路径,未找到返回None
"""
# 基础libs目录
libs_dir = os.path.join(APP_DIR, "libs")
if not os.path.exists(libs_dir):
logger.error(f"未找到libs目录: {libs_dir}")
return None
# 如果指定了系统和架构,查找具体的子目录
if system and arch:
specific_dir = os.path.join(libs_dir, system, arch)
logger.info(f"spec: {specific_dir}")
if os.path.isdir(specific_dir):
return specific_dir
elif system:
system_dir = os.path.join(libs_dir, system)
if os.path.isdir(system_dir):
return system_dir
return libs_dir