Skip to content

Commit acf5fde

Browse files
committed
Add startup_json_path, disable_browser, port config
1 parent 7f7b1c1 commit acf5fde

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

unilabos/app/main.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def parse_args():
105105
parser.add_argument(
106106
"--port",
107107
type=int,
108-
default=8002,
108+
default=None,
109109
help="Port for web service information page",
110110
)
111111
parser.add_argument(
@@ -252,6 +252,8 @@ def main():
252252
else:
253253
print_status("远程资源不存在,本地将进行首次上报!", "info")
254254

255+
BasicConfig.port = args_dict["port"] if args_dict["port"] else BasicConfig.port
256+
BasicConfig.disable_browser = args_dict["disable_browser"] or BasicConfig.disable_browser
255257
BasicConfig.working_dir = working_dir
256258
BasicConfig.is_host_mode = not args_dict.get("is_slave", False)
257259
BasicConfig.slave_no_host = args_dict.get("slave_no_host", False)
@@ -291,7 +293,9 @@ def main():
291293
resource_tree_set: ResourceTreeSet
292294
resource_links: List[Dict[str, Any]]
293295
request_startup_json = http_client.request_startup_json()
294-
if args_dict["graph"] is None:
296+
297+
file_path = args_dict.get("graph", BasicConfig.startup_json_path)
298+
if file_path is None:
295299
if not request_startup_json:
296300
print_status(
297301
"未指定设备加载文件路径,尝试从HTTP获取失败,请检查网络或者使用-g参数指定设备加载文件路径", "error"
@@ -301,7 +305,6 @@ def main():
301305
print_status("联网获取设备加载文件成功", "info")
302306
graph, resource_tree_set, resource_links = read_node_link_json(request_startup_json)
303307
else:
304-
file_path = args_dict["graph"]
305308
if not os.path.isfile(file_path):
306309
temp_file_path = os.path.abspath(str(os.path.join(__file__, "..", "..", file_path)))
307310
if os.path.isfile(temp_file_path):
@@ -418,8 +421,8 @@ def _exit(signum, frame):
418421
server_thread = threading.Thread(
419422
target=start_server,
420423
kwargs=dict(
421-
open_browser=not args_dict["disable_browser"],
422-
port=args_dict["port"],
424+
open_browser=not BasicConfig.disable_browser,
425+
port=BasicConfig.port,
423426
),
424427
)
425428
server_thread.start()

unilabos/config/config.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ class BasicConfig:
1818
vis_2d_enable = False
1919
enable_resource_load = True
2020
communication_protocol = "websocket"
21+
startup_json_path = None # 填写绝对路径
22+
disable_browser = False # 禁止浏览器自动打开
23+
port = 8002 # 本地HTTP服务
2124
log_level: Literal['TRACE', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'] = "DEBUG" # 'TRACE', 'DEBUG', 'INFO', 'WARNING', 'ERROR', 'CRITICAL'
2225

2326
@classmethod

0 commit comments

Comments
 (0)