mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2025-12-17 21:11:12 +00:00
feat(main): enhance argument parsing for addr and port with priority handling
This commit is contained in:
@@ -105,7 +105,7 @@ def parse_args():
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--port",
|
"--port",
|
||||||
type=int,
|
type=int,
|
||||||
default=8002,
|
default=None,
|
||||||
help="Port for web service information page",
|
help="Port for web service information page",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -139,7 +139,7 @@ def parse_args():
|
|||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
"--addr",
|
"--addr",
|
||||||
type=str,
|
type=str,
|
||||||
default="https://uni-lab.bohrium.com/api/v1",
|
default=None,
|
||||||
help="Laboratory backend address",
|
help="Laboratory backend address",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
@@ -220,17 +220,53 @@ def main():
|
|||||||
logger.info(f"Log level set to '{BasicConfig.log_level}' from config file.")
|
logger.info(f"Log level set to '{BasicConfig.log_level}' from config file.")
|
||||||
configure_logger(loglevel=BasicConfig.log_level)
|
configure_logger(loglevel=BasicConfig.log_level)
|
||||||
|
|
||||||
if args_dict["addr"] == "test":
|
# 选择地址优先级:命令行 > 配置文件 > 默认线上
|
||||||
|
addr_cli = args_dict.get("addr", None)
|
||||||
|
addr_cfg = getattr(BasicConfig, "addr", None)
|
||||||
|
effective_addr = addr_cli if (addr_cli not in (None, "")) else addr_cfg
|
||||||
|
|
||||||
|
if effective_addr == "test":
|
||||||
print_status("使用测试环境地址", "info")
|
print_status("使用测试环境地址", "info")
|
||||||
HTTPConfig.remote_addr = "https://uni-lab.test.bohrium.com/api/v1"
|
HTTPConfig.remote_addr = "https://uni-lab.test.bohrium.com/api/v1"
|
||||||
elif args_dict["addr"] == "uat":
|
elif effective_addr == "uat":
|
||||||
print_status("使用uat环境地址", "info")
|
print_status("使用uat环境地址", "info")
|
||||||
HTTPConfig.remote_addr = "https://uni-lab.uat.bohrium.com/api/v1"
|
HTTPConfig.remote_addr = "https://uni-lab.uat.bohrium.com/api/v1"
|
||||||
elif args_dict["addr"] == "local":
|
elif effective_addr == "local":
|
||||||
print_status("使用本地环境地址", "info")
|
print_status("使用本地环境地址", "info")
|
||||||
HTTPConfig.remote_addr = "http://127.0.0.1:48197/api/v1"
|
HTTPConfig.remote_addr = "http://127.0.0.1:48197/api/v1"
|
||||||
|
elif effective_addr:
|
||||||
|
HTTPConfig.remote_addr = effective_addr
|
||||||
|
print_status(f"使用配置/命令行提供的自定义地址: {effective_addr}", "info")
|
||||||
else:
|
else:
|
||||||
HTTPConfig.remote_addr = args_dict.get("addr", "")
|
# 默认地址
|
||||||
|
HTTPConfig.remote_addr = "https://uni-lab.bohrium.com/api/v1"
|
||||||
|
print_status("未提供地址,使用默认线上地址", "info")
|
||||||
|
|
||||||
|
# 选择端口优先级:命令行 > 配置文件 > 默认 8002
|
||||||
|
port_cli = args_dict.get("port", None)
|
||||||
|
port_cfg = getattr(BasicConfig, "port", None) if hasattr(BasicConfig, "port") else None
|
||||||
|
effective_port = port_cli if (port_cli is not None) else (port_cfg if (port_cfg is not None) else 8002)
|
||||||
|
args_dict["port"] = effective_port
|
||||||
|
if port_cli is not None:
|
||||||
|
print_status(f"使用命令行端口 {effective_port}", "info")
|
||||||
|
elif port_cfg is not None:
|
||||||
|
print_status(f"使用配置文件端口 {effective_port}", "info")
|
||||||
|
else:
|
||||||
|
print_status(f"未提供端口,使用默认端口 {effective_port}", "info")
|
||||||
|
|
||||||
|
# 选择是否打开浏览器:命令行(是否包含 --disable_browser) > 配置文件 > 默认 False
|
||||||
|
disable_browser_cli = "--disable_browser" in sys.argv
|
||||||
|
if disable_browser_cli:
|
||||||
|
args_dict["disable_browser"] = True
|
||||||
|
print_status("使用命令行设置:禁用浏览器", "info")
|
||||||
|
else:
|
||||||
|
disable_cfg = getattr(BasicConfig, "disable_browser", None)
|
||||||
|
if isinstance(disable_cfg, bool):
|
||||||
|
args_dict["disable_browser"] = disable_cfg
|
||||||
|
print_status(f"使用配置文件设置:disable_browser={disable_cfg}", "info")
|
||||||
|
else:
|
||||||
|
args_dict["disable_browser"] = False
|
||||||
|
print_status("未提供 disable_browser,默认开启浏览器", "info")
|
||||||
|
|
||||||
# 设置BasicConfig参数
|
# 设置BasicConfig参数
|
||||||
if args_dict.get("ak", ""):
|
if args_dict.get("ak", ""):
|
||||||
|
|||||||
Reference in New Issue
Block a user