mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2026-02-07 15:35:10 +00:00
新增lab_id直接传入
This commit is contained in:
@@ -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
|
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:
|
if config_path is None:
|
||||||
config_path = os.environ.get("UNILABOS.BASICCONFIG.CONFIG_PATH", None)
|
config_path = os.environ.get("UNILABOS.BASICCONFIG.CONFIG_PATH", None)
|
||||||
if config_path:
|
if config_path:
|
||||||
@@ -31,10 +31,10 @@ def load_config_from_file(config_path):
|
|||||||
elif not config_path.endswith(".py"):
|
elif not config_path.endswith(".py"):
|
||||||
print_status(f"配置文件 {config_path} 不是Python文件,必须以.py结尾", "error")
|
print_status(f"配置文件 {config_path} 不是Python文件,必须以.py结尾", "error")
|
||||||
else:
|
else:
|
||||||
load_config(config_path)
|
load_config(config_path, override_labid)
|
||||||
else:
|
else:
|
||||||
print_status(f"启动 UniLab-OS时,配置文件参数未正确传入 --config '{config_path}' 尝试本地配置...", "warning")
|
print_status(f"启动 UniLab-OS时,配置文件参数未正确传入 --config '{config_path}' 尝试本地配置...", "warning")
|
||||||
load_config(config_path)
|
load_config(config_path, override_labid)
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
@@ -106,6 +106,12 @@ def parse_args():
|
|||||||
default="disable",
|
default="disable",
|
||||||
help="选择可视化工具: rviz, web",
|
help="选择可视化工具: rviz, web",
|
||||||
)
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--labid",
|
||||||
|
type=str,
|
||||||
|
default="",
|
||||||
|
help="实验室唯一ID,也可通过环境变量 UNILABOS.MQCONFIG.LABID 设置或传入--config设置",
|
||||||
|
)
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
@@ -117,7 +123,7 @@ def main():
|
|||||||
|
|
||||||
# 加载配置文件,优先加载config,然后从env读取
|
# 加载配置文件,优先加载config,然后从env读取
|
||||||
config_path = args_dict.get("config")
|
config_path = args_dict.get("config")
|
||||||
load_config_from_file(config_path)
|
load_config_from_file(config_path, args_dict["labid"])
|
||||||
|
|
||||||
# 设置BasicConfig参数
|
# 设置BasicConfig参数
|
||||||
BasicConfig.is_host_mode = not args_dict.get("without_host", False)
|
BasicConfig.is_host_mode = not args_dict.get("without_host", False)
|
||||||
|
|||||||
@@ -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():
|
for name, obj in globals().items():
|
||||||
if isinstance(obj, type) and name.endswith("Config"):
|
if isinstance(obj, type) and name.endswith("Config"):
|
||||||
if hasattr(module, name) and isinstance(getattr(module, name), type):
|
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:
|
if len(OSSUploadConfig.authorization) == 0:
|
||||||
OSSUploadConfig.authorization = f"lab {MQConfig.lab_id}"
|
OSSUploadConfig.authorization = f"lab {MQConfig.lab_id}"
|
||||||
# 对 ca_file cert_file key_file 进行初始化
|
# 对 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 len(MQConfig.ca_content) == 0:
|
||||||
# 需要先判断是否为相对路径
|
# 需要先判断是否为相对路径
|
||||||
if MQConfig.ca_file.startswith("."):
|
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:
|
if config_path:
|
||||||
_update_config_from_env() # 允许config_path被env设定后读取
|
_update_config_from_env() # 允许config_path被env设定后读取
|
||||||
@@ -172,7 +175,7 @@ def load_config(config_path=None):
|
|||||||
return
|
return
|
||||||
module = importlib.util.module_from_spec(spec)
|
module = importlib.util.module_from_spec(spec)
|
||||||
spec.loader.exec_module(module) # type: ignore
|
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} 加载成功")
|
logger.info(f"[ENV] 配置文件 {config_path} 加载成功")
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.error(f"[ENV] 加载配置文件 {config_path} 失败")
|
logger.error(f"[ENV] 加载配置文件 {config_path} 失败")
|
||||||
@@ -180,4 +183,4 @@ def load_config(config_path=None):
|
|||||||
exit(1)
|
exit(1)
|
||||||
else:
|
else:
|
||||||
config_path = os.path.join(os.path.dirname(__file__), "local_config.py")
|
config_path = os.path.join(os.path.dirname(__file__), "local_config.py")
|
||||||
load_config(config_path)
|
load_config(config_path, override_labid)
|
||||||
|
|||||||
@@ -2187,65 +2187,65 @@ virtual_multiway_valve:
|
|||||||
data_source: executor
|
data_source: executor
|
||||||
data_type: fluid
|
data_type: fluid
|
||||||
description: 八通阀门端口1
|
description: 八通阀门端口1
|
||||||
handler_key: "1"
|
handler_key: '1'
|
||||||
io_type: source
|
io_type: source
|
||||||
label: "1"
|
label: '1'
|
||||||
side: NORTH
|
side: NORTH
|
||||||
- data_key: fluid_port_2
|
- data_key: fluid_port_2
|
||||||
data_source: executor
|
data_source: executor
|
||||||
data_type: fluid
|
data_type: fluid
|
||||||
description: 八通阀门端口2
|
description: 八通阀门端口2
|
||||||
handler_key: "2"
|
handler_key: '2'
|
||||||
io_type: source
|
io_type: source
|
||||||
label: "2"
|
label: '2'
|
||||||
side: EAST
|
side: EAST
|
||||||
- data_key: fluid_port_3
|
- data_key: fluid_port_3
|
||||||
data_source: executor
|
data_source: executor
|
||||||
data_type: fluid
|
data_type: fluid
|
||||||
description: 八通阀门端口3
|
description: 八通阀门端口3
|
||||||
handler_key: "3"
|
handler_key: '3'
|
||||||
io_type: source
|
io_type: source
|
||||||
label: "3"
|
label: '3'
|
||||||
side: EAST
|
side: EAST
|
||||||
- data_key: fluid_port_4
|
- data_key: fluid_port_4
|
||||||
data_source: executor
|
data_source: executor
|
||||||
data_type: fluid
|
data_type: fluid
|
||||||
description: 八通阀门端口4
|
description: 八通阀门端口4
|
||||||
handler_key: "4"
|
handler_key: '4'
|
||||||
io_type: source
|
io_type: source
|
||||||
label: "4"
|
label: '4'
|
||||||
side: SOUTH
|
side: SOUTH
|
||||||
- data_key: fluid_port_5
|
- data_key: fluid_port_5
|
||||||
data_source: executor
|
data_source: executor
|
||||||
data_type: fluid
|
data_type: fluid
|
||||||
description: 八通阀门端口5
|
description: 八通阀门端口5
|
||||||
handler_key: "5"
|
handler_key: '5'
|
||||||
io_type: source
|
io_type: source
|
||||||
label: "5"
|
label: '5'
|
||||||
side: SOUTH
|
side: SOUTH
|
||||||
- data_key: fluid_port_6
|
- data_key: fluid_port_6
|
||||||
data_source: executor
|
data_source: executor
|
||||||
data_type: fluid
|
data_type: fluid
|
||||||
description: 八通阀门端口6
|
description: 八通阀门端口6
|
||||||
handler_key: "6"
|
handler_key: '6'
|
||||||
io_type: source
|
io_type: source
|
||||||
label: "6"
|
label: '6'
|
||||||
side: WEST
|
side: WEST
|
||||||
- data_key: fluid_port_7
|
- data_key: fluid_port_7
|
||||||
data_source: executor
|
data_source: executor
|
||||||
data_type: fluid
|
data_type: fluid
|
||||||
description: 八通阀门端口7
|
description: 八通阀门端口7
|
||||||
handler_key: "7"
|
handler_key: '7'
|
||||||
io_type: source
|
io_type: source
|
||||||
label: "7"
|
label: '7'
|
||||||
side: WEST
|
side: WEST
|
||||||
- data_key: fluid_port_8
|
- data_key: fluid_port_8
|
||||||
data_source: executor
|
data_source: executor
|
||||||
data_type: fluid
|
data_type: fluid
|
||||||
description: 八通阀门端口8
|
description: 八通阀门端口8
|
||||||
handler_key: "8"
|
handler_key: '8'
|
||||||
io_type: source
|
io_type: source
|
||||||
label: "8"
|
label: '8'
|
||||||
side: NORTH
|
side: NORTH
|
||||||
icon: EightPipeline.webp
|
icon: EightPipeline.webp
|
||||||
init_param_schema:
|
init_param_schema:
|
||||||
|
|||||||
Reference in New Issue
Block a user