feat: 支持local_config启动

add: 增加对crt path的说明,为传入config.py的相对路径
move: web component
This commit is contained in:
wznln
2025-04-20 18:11:35 +08:00
parent bb1cac0dbd
commit 82881f5882
19 changed files with 33 additions and 31 deletions

2
.gitignore vendored
View File

@@ -229,6 +229,6 @@ CATKIN_IGNORE
.DS_Store
local_config.py
/**/local_config.py
*.graphml

View File

@@ -1 +1,3 @@
recursive-include unilabos/registry *.yaml
recursive-include unilabos/app/web *.html
recursive-include unilabos/app/web *.css

View File

@@ -46,9 +46,9 @@ class MQConfig:
port: int = 8883
# 可以直接提供证书文件路径
ca_file: str = "/path/to/ca.pem"
cert_file: str = "/path/to/cert.pem"
key_file: str = "/path/to/key.pem"
ca_file: str = "/path/to/ca.pem" # 相对config.py所在目录的路径
cert_file: str = "/path/to/cert.pem" # 相对config.py所在目录的路径
key_file: str = "/path/to/key.pem" # 相对config.py所在目录的路径
# 或者直接提供证书内容
ca_content: str = ""
@@ -102,6 +102,8 @@ class ROSConfig:
unilab --config path/to/your/config.py
```
如果您不涉及多环境开发可以在unilabos的安装路径中手动添加local_config.py的文件
# 启动Uni-Lab
python -m unilabos.app.main --config path/to/your/config.py
```

View File

@@ -69,14 +69,17 @@ def main():
args_dict = vars(args)
# 加载配置文件 - 这里保持最先加载配置的逻辑
if args_dict.get("config"):
config_path = args_dict["config"]
config_path = args_dict.get("config")
if config_path:
if not os.path.exists(config_path):
print_status(f"配置文件 {config_path} 不存在", "error")
elif not config_path.endswith(".py"):
print_status(f"配置文件 {config_path} 不是Python文件必须以.py结尾", "error")
else:
load_config(config_path)
else:
print_status(f"启动 UniLab-OS时配置文件参数未正确传入 --config '{config_path}' 尝试本地配置...", "warning")
load_config(config_path)
# 设置BasicConfig参数
BasicConfig.is_host_mode = not args_dict.get("without_host", False)
@@ -92,8 +95,8 @@ def main():
from unilabos.app.mq import mqtt_client
from unilabos.registry.registry import build_registry
from unilabos.app.backend import start_backend
from unilabos.web import http_client
from unilabos.web import start_server
from unilabos.app.web import http_client
from unilabos.app.web import start_server
# 显示启动横幅
print_unilab_banner(args_dict)

View File

@@ -4,10 +4,10 @@ Web UI 模块
提供了UniLab系统的Web界面功能
"""
from unilabos.web.pages import setup_web_pages
from unilabos.web.server import setup_server, start_server
from unilabos.web.client import http_client
from unilabos.web.api import setup_api_routes
from unilabos.app.web.pages import setup_web_pages
from unilabos.app.web.server import setup_server, start_server
from unilabos.app.web.client import http_client
from unilabos.app.web.api import setup_api_routes
__all__ = [
"setup_web_pages", # 设置Web页面

View File

@@ -18,7 +18,7 @@ from unilabos.app.model import (
JobPreintakeFinishReq,
JobFinishReq,
)
from unilabos.web.utils.host_utils import get_host_node_info
from unilabos.app.web.utils.host_utils import get_host_node_info
# 创建API路由器
api = APIRouter()

View File

@@ -20,9 +20,9 @@ from unilabos.app.mq import mqtt_client
from unilabos.ros.msgs.message_converter import msg_converter_manager
from unilabos.utils.log import error
from unilabos.utils.type_check import TypeEncoder
from unilabos.web.utils.device_utils import get_registry_info
from unilabos.web.utils.host_utils import get_host_node_info
from unilabos.web.utils.ros_utils import get_ros_node_info, update_ros_node_info
from unilabos.app.web.utils.device_utils import get_registry_info
from unilabos.app.web.utils.host_utils import get_host_node_info
from unilabos.app.web.utils.ros_utils import get_ros_node_info, update_ros_node_info
# 设置Jinja2模板环境
template_dir = Path(__file__).parent / "templates"

View File

@@ -13,8 +13,8 @@ from starlette.responses import Response
from unilabos.utils.fastapi.log_adapter import setup_fastapi_logging
from unilabos.utils.log import info, error
from unilabos.web.api import setup_api_routes
from unilabos.web.pages import setup_web_pages
from unilabos.app.web.api import setup_api_routes
from unilabos.app.web.pages import setup_web_pages
# 创建FastAPI应用
app = FastAPI(

View File

@@ -9,7 +9,7 @@ from typing import Dict, Any
from unilabos.config.config import BasicConfig
from unilabos.ros.nodes.presets.host_node import HostNode
from unilabos.web.utils.action_utils import get_action_info
from unilabos.app.web.utils.action_utils import get_action_info
def get_host_node_info() -> Dict[str, Any]:

View File

@@ -7,7 +7,7 @@ ROS 工具函数模块
import traceback
from typing import Dict, Any
from unilabos.web.utils.action_utils import get_action_info
from unilabos.app.web.utils.action_utils import get_action_info
# 存储 ROS 节点信息的全局变量
ros_node_info = {"online_devices": {}, "device_topics": {}, "device_actions": {}}

View File

@@ -28,9 +28,9 @@ class MQConfig:
key_content = ""
# 指定
ca_file = ""
cert_file = ""
key_file = ""
ca_file = "" # 相对config.py所在目录的路径
cert_file = "" # 相对config.py所在目录的路径
key_file = "" # 相对config.py所在目录的路径
# OSS上传配置
@@ -97,7 +97,7 @@ def load_config(config_path=None):
BasicConfig.config_path = os.path.abspath(os.path.dirname(config_path))
if not os.path.exists(config_path):
logger.error(f"配置文件 {config_path} 不存在")
return
exit(1)
try:
module_name = "lab_" + os.path.basename(config_path).replace(".py", "")
@@ -114,10 +114,5 @@ def load_config(config_path=None):
traceback.print_exc()
exit(1)
else:
try:
import unilabos.config.local_config as local_config # type: ignore
_update_config_from_module(local_config)
logger.info("已加载默认配置 unilabos.config.local_config")
except ImportError:
pass
config_path = os.path.join(os.path.dirname(__file__), "local_config.py")
load_config(config_path)