新增用户引导

This commit is contained in:
Xuwznln
2025-08-01 01:01:29 +08:00
parent 2580e80d6f
commit b63e281ab7
4 changed files with 44 additions and 0 deletions

1
.gitignore vendored
View File

@@ -1,6 +1,7 @@
configs/ configs/
temp/ temp/
output/ output/
unilabos_data/
## Python ## Python
# Byte-compiled / optimized / DLL files # Byte-compiled / optimized / DLL files

View File

@@ -1,6 +1,7 @@
import argparse import argparse
import asyncio import asyncio
import os import os
import shutil
import signal import signal
import sys import sys
import threading import threading
@@ -139,9 +140,33 @@ def main():
# 加载配置文件优先加载config然后从env读取 # 加载配置文件优先加载config然后从env读取
config_path = args_dict.get("config") config_path = args_dict.get("config")
working_dir = os.path.abspath(os.path.join(os.getcwd(), "unilabos_data"))
if not config_path and (not os.path.exists(working_dir) or not os.path.exists(os.path.join(working_dir, "local_config.py"))):
print_status(f"当前未指定config路径非第一次使用请通过 --config 传入 local_config.py 文件路径", "info")
print_status(f"您是否为第一次使用?并将当前文件路径 {working_dir} 作为工作目录? (Y/n)", "info")
if input() != "n":
os.makedirs(working_dir, exist_ok=True)
config_path = os.path.join(working_dir, "local_config.py")
shutil.copy(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)
else:
working_dir = args_dict.get("working_dir") or os.path.abspath(os.path.join(os.getcwd(), "unilabos_data"))
if working_dir:
if config_path and not os.path.exists(config_path):
config_path = os.path.join(working_dir, "local_config.py")
if not os.path.exists(config_path):
print_status(f"当前工作目录 {working_dir} 未找到local_config.py请通过 --config 传入 local_config.py 文件路径", "error")
os._exit(1)
print_status(f"当前工作目录为 {working_dir}", "info")
# 加载配置文件
load_config_from_file(config_path, args_dict["labid"]) load_config_from_file(config_path, args_dict["labid"])
# 设置BasicConfig参数 # 设置BasicConfig参数
BasicConfig.working_dir = working_dir
BasicConfig.is_host_mode = not args_dict.get("without_host", False) BasicConfig.is_host_mode = not args_dict.get("without_host", False)
BasicConfig.slave_no_host = args_dict.get("slave_no_host", False) BasicConfig.slave_no_host = args_dict.get("slave_no_host", False)
BasicConfig.upload_registry = args_dict.get("upload_registry", False) BasicConfig.upload_registry = args_dict.get("upload_registry", False)

View File

@@ -9,6 +9,7 @@ from unilabos.utils import logger
class BasicConfig: class BasicConfig:
ENV = "pro" # 'test' ENV = "pro" # 'test'
working_dir = ""
config_path = "" config_path = ""
is_host_mode = True is_host_mode = True
slave_no_host = False # 是否跳过rclient.wait_for_service() slave_no_host = False # 是否跳过rclient.wait_for_service()

View File

@@ -0,0 +1,17 @@
# 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"