From 22b88c84411bb5fc6366837c716d991a787f0557 Mon Sep 17 00:00:00 2001 From: Xuwznln <18435084+Xuwznln@users.noreply.github.com> Date: Wed, 10 Sep 2025 20:55:24 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=96=E6=B6=88labid=20=E5=92=8C=20=E5=BC=BA?= =?UTF-8?q?=E5=88=B6config=E8=BE=93=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- unilabos/app/main.py | 17 ++++--------- unilabos/config/config.py | 40 ++++--------------------------- unilabos/config/example_config.py | 19 +-------------- 3 files changed, 9 insertions(+), 67 deletions(-) diff --git a/unilabos/app/main.py b/unilabos/app/main.py index c70787e1..6377d864 100644 --- a/unilabos/app/main.py +++ b/unilabos/app/main.py @@ -22,7 +22,7 @@ from unilabos.utils.banner_print import print_status, print_unilab_banner from unilabos.resources.graphio import modify_to_backend_format -def load_config_from_file(config_path, override_labid=None): +def load_config_from_file(config_path): 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, override_labid=None): elif not config_path.endswith(".py"): print_status(f"配置文件 {config_path} 不是Python文件,必须以.py结尾", "error") else: - load_config(config_path, override_labid) + load_config(config_path) else: print_status(f"启动 UniLab-OS时,配置文件参数未正确传入 --config '{config_path}' 尝试本地配置...", "warning") - load_config(config_path, override_labid) + load_config(config_path) def convert_argv_dashes_to_underscores(args: argparse.ArgumentParser): @@ -52,8 +52,6 @@ def parse_args(): """解析命令行参数""" parser = argparse.ArgumentParser(description="Start Uni-Lab Edge server.") parser.add_argument("-g", "--graph", help="Physical setup graph.") - # parser.add_argument("-d", "--devices", help="Devices config file.") - # parser.add_argument("-r", "--resources", help="Resources config file.") parser.add_argument("-c", "--controllers", default=None, help="Controllers config file.") parser.add_argument( "--registry_path", @@ -128,12 +126,6 @@ def parse_args(): default="disable", help="选择可视化工具: rviz, web", ) - parser.add_argument( - "--labid", - type=str, - default="", - help="实验室唯一ID,也可通过环境变量 UNILABOS_MQCONFIG_LABID 设置或传入--config设置", - ) parser.add_argument( "--ak", type=str, @@ -215,13 +207,12 @@ def main(): os.path.join(os.path.dirname(os.path.dirname(__file__)), "config", "example_config.py"), config_path ) print_status(f"已创建 local_config.py 路径: {config_path}", "info") - print_status(f"请在文件夹中配置lab_id,放入下载的CA.crt、lab.crt、lab.key重新启动本程序", "info") os._exit(1) else: os._exit(1) # 加载配置文件 print_status(f"当前工作目录为 {working_dir}", "info") - load_config_from_file(config_path, args_dict["labid"]) + load_config_from_file(config_path) if args_dict["addr"] == "test": print_status("使用测试环境地址", "info") HTTPConfig.remote_addr = "https://uni-lab.test.bohrium.com/api/v1" diff --git a/unilabos/config/config.py b/unilabos/config/config.py index 99c31eea..6fe972f0 100644 --- a/unilabos/config/config.py +++ b/unilabos/config/config.py @@ -87,7 +87,7 @@ class ROSConfig: ] -def _update_config_from_module(module, override_labid: Optional[str]): +def _update_config_from_module(module): for name, obj in globals().items(): if isinstance(obj, type) and name.endswith("Config"): if hasattr(module, name) and isinstance(getattr(module, name), type): @@ -97,38 +97,6 @@ def _update_config_from_module(module, override_labid: Optional[str]): # 更新OSS认证 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("."): - MQConfig.ca_file = os.path.join(BasicConfig.config_path, MQConfig.ca_file) - if len(MQConfig.ca_file) != 0: - with open(MQConfig.ca_file, "r", encoding="utf-8") as f: - MQConfig.ca_content = f.read() - else: - logger.warning("Skipping CA file loading, ca_file is empty") - if len(MQConfig.cert_content) == 0: - # 需要先判断是否为相对路径 - if MQConfig.cert_file.startswith("."): - MQConfig.cert_file = os.path.join(BasicConfig.config_path, MQConfig.cert_file) - if len(MQConfig.ca_file) != 0: - with open(MQConfig.cert_file, "r", encoding="utf-8") as f: - MQConfig.cert_content = f.read() - else: - logger.warning("Skipping cert file loading, cert_file is empty") - if len(MQConfig.key_content) == 0: - # 需要先判断是否为相对路径 - if MQConfig.key_file.startswith("."): - MQConfig.key_file = os.path.join(BasicConfig.config_path, MQConfig.key_file) - if len(MQConfig.ca_file) != 0: - with open(MQConfig.key_file, "r", encoding="utf-8") as f: - MQConfig.key_content = f.read() - else: - logger.warning("Skipping key file loading, key_file is empty") - def _update_config_from_env(): prefix = "UNILABOS_" @@ -181,7 +149,7 @@ def _update_config_from_env(): logger.warning(f"[ENV] 解析环境变量 {env_key} 失败: {e}") -def load_config(config_path=None, override_labid=None): +def load_config(config_path=None): # 如果提供了配置文件路径,从该文件导入配置 if config_path: env_config_path = os.environ.get("UNILABOS_BASICCONFIG_CONFIG_PATH") @@ -198,7 +166,7 @@ def load_config(config_path=None, override_labid=None): return module = importlib.util.module_from_spec(spec) spec.loader.exec_module(module) # type: ignore - _update_config_from_module(module, override_labid) + _update_config_from_module(module) logger.info(f"[ENV] 配置文件 {config_path} 加载成功") _update_config_from_env() except Exception as e: @@ -207,4 +175,4 @@ def load_config(config_path=None, override_labid=None): exit(1) else: config_path = os.path.join(os.path.dirname(__file__), "local_config.py") - load_config(config_path, override_labid) + load_config(config_path) diff --git a/unilabos/config/example_config.py b/unilabos/config/example_config.py index 07018cba..649a0606 100644 --- a/unilabos/config/example_config.py +++ b/unilabos/config/example_config.py @@ -1,18 +1 @@ -# MQTT配置 -class MQConfig: - lab_id = "" - instance_id = "" - access_key = "" - secret_key = "" - group_id = "" - broker_url = "" - port = 1883 - - ca_file = "./CA.crt" - cert_file = "./lab.crt" - key_file = "./lab.key" - - -# HTTP配置 -class HTTPConfig: - remote_addr = "https://uni-lab.bohrium.com/api/v1" +# 暂无配置 \ No newline at end of file