新增lab_id直接传入

This commit is contained in:
Xuwznln
2025-07-25 15:23:35 +08:00
parent d289c01a34
commit 1b086a85f5
3 changed files with 33 additions and 24 deletions

View File

@@ -22,7 +22,7 @@ from unilabos.config.config import load_config, BasicConfig, _update_config_from
from unilabos.utils.banner_print import print_status, print_unilab_banner
def load_config_from_file(config_path):
def load_config_from_file(config_path, override_labid=None):
if config_path is None:
config_path = os.environ.get("UNILABOS.BASICCONFIG.CONFIG_PATH", None)
if config_path:
@@ -31,10 +31,10 @@ def load_config_from_file(config_path):
elif not config_path.endswith(".py"):
print_status(f"配置文件 {config_path} 不是Python文件必须以.py结尾", "error")
else:
load_config(config_path)
load_config(config_path, override_labid)
else:
print_status(f"启动 UniLab-OS时配置文件参数未正确传入 --config '{config_path}' 尝试本地配置...", "warning")
load_config(config_path)
load_config(config_path, override_labid)
def parse_args():
@@ -106,6 +106,12 @@ def parse_args():
default="disable",
help="选择可视化工具: rviz, web",
)
parser.add_argument(
"--labid",
type=str,
default="",
help="实验室唯一ID也可通过环境变量 UNILABOS.MQCONFIG.LABID 设置或传入--config设置",
)
return parser.parse_args()
@@ -117,7 +123,7 @@ def main():
# 加载配置文件优先加载config然后从env读取
config_path = args_dict.get("config")
load_config_from_file(config_path)
load_config_from_file(config_path, args_dict["labid"])
# 设置BasicConfig参数
BasicConfig.is_host_mode = not args_dict.get("without_host", False)

View File

@@ -63,7 +63,7 @@ class ROSConfig:
]
def _update_config_from_module(module):
def _update_config_from_module(module, override_labid: str):
for name, obj in globals().items():
if isinstance(obj, type) and name.endswith("Config"):
if hasattr(module, name) and isinstance(getattr(module, name), type):
@@ -74,6 +74,9 @@ def _update_config_from_module(module):
if len(OSSUploadConfig.authorization) == 0:
OSSUploadConfig.authorization = f"lab {MQConfig.lab_id}"
# 对 ca_file cert_file key_file 进行初始化
if override_labid:
MQConfig.lab_id = override_labid
logger.warning(f"[ENV] 当前实验室启动的ID被设置为{override_labid}")
if len(MQConfig.ca_content) == 0:
# 需要先判断是否为相对路径
if MQConfig.ca_file.startswith("."):
@@ -155,7 +158,7 @@ def _update_config_from_env():
def load_config(config_path=None):
def load_config(config_path=None, override_labid=None):
# 如果提供了配置文件路径,从该文件导入配置
if config_path:
_update_config_from_env() # 允许config_path被env设定后读取
@@ -172,7 +175,7 @@ def load_config(config_path=None):
return
module = importlib.util.module_from_spec(spec)
spec.loader.exec_module(module) # type: ignore
_update_config_from_module(module)
_update_config_from_module(module, override_labid)
logger.info(f"[ENV] 配置文件 {config_path} 加载成功")
except Exception as e:
logger.error(f"[ENV] 加载配置文件 {config_path} 失败")
@@ -180,4 +183,4 @@ def load_config(config_path=None):
exit(1)
else:
config_path = os.path.join(os.path.dirname(__file__), "local_config.py")
load_config(config_path)
load_config(config_path, override_labid)

View File

@@ -2187,65 +2187,65 @@ virtual_multiway_valve:
data_source: executor
data_type: fluid
description: 八通阀门端口1
handler_key: "1"
handler_key: '1'
io_type: source
label: "1"
label: '1'
side: NORTH
- data_key: fluid_port_2
data_source: executor
data_type: fluid
description: 八通阀门端口2
handler_key: "2"
handler_key: '2'
io_type: source
label: "2"
label: '2'
side: EAST
- data_key: fluid_port_3
data_source: executor
data_type: fluid
description: 八通阀门端口3
handler_key: "3"
handler_key: '3'
io_type: source
label: "3"
label: '3'
side: EAST
- data_key: fluid_port_4
data_source: executor
data_type: fluid
description: 八通阀门端口4
handler_key: "4"
handler_key: '4'
io_type: source
label: "4"
label: '4'
side: SOUTH
- data_key: fluid_port_5
data_source: executor
data_type: fluid
description: 八通阀门端口5
handler_key: "5"
handler_key: '5'
io_type: source
label: "5"
label: '5'
side: SOUTH
- data_key: fluid_port_6
data_source: executor
data_type: fluid
description: 八通阀门端口6
handler_key: "6"
handler_key: '6'
io_type: source
label: "6"
label: '6'
side: WEST
- data_key: fluid_port_7
data_source: executor
data_type: fluid
description: 八通阀门端口7
handler_key: "7"
handler_key: '7'
io_type: source
label: "7"
label: '7'
side: WEST
- data_key: fluid_port_8
data_source: executor
data_type: fluid
description: 八通阀门端口8
handler_key: "8"
handler_key: '8'
io_type: source
label: "8"
label: '8'
side: NORTH
icon: EightPipeline.webp
init_param_schema: