From 5408317ee51194f74cfe271cc7cb84bae3a9bd89 Mon Sep 17 00:00:00 2001 From: Dustella Date: Thu, 20 Mar 2025 17:03:16 +0800 Subject: [PATCH] windows path fix --- .gitignore | 3 +++ backend.py | 3 +-- modules/balloon/__init__.py | 3 ++- modules/tidi/__init__.py | 3 ++- run-linux.sh | 19 +++++++++++++++++++ run-windows.bat | 24 ++++++++++++++++++++++++ 6 files changed, 51 insertions(+), 4 deletions(-) create mode 100644 run-linux.sh create mode 100644 run-windows.bat diff --git a/.gitignore b/.gitignore index cbaf0ad..99c405e 100644 --- a/.gitignore +++ b/.gitignore @@ -22,6 +22,9 @@ dist notebooks passcode data +windows +linux +*.7z *.7z res *.txt diff --git a/backend.py b/backend.py index 8489a7f..aff8663 100644 --- a/backend.py +++ b/backend.py @@ -1,5 +1,4 @@ import os -import resource from matplotlib import pyplot as plt from modules import cosmic from modules import tidi @@ -77,6 +76,6 @@ if __name__ == '__main__': env_port = os.getenv("Z_PORT") port = 5000 if env_port is None else int(env_port) if 'debug' in args: - app.run("0.0.0.0", port=58620, debug=True) + app.run("0.0.0.0", port=port, debug=True) else: app.run("0.0.0.0", port=port, debug=False) diff --git a/modules/balloon/__init__.py b/modules/balloon/__init__.py index e698aa0..923f9fe 100644 --- a/modules/balloon/__init__.py +++ b/modules/balloon/__init__.py @@ -33,7 +33,8 @@ def supermeta(): def list_ballon(): all_ballon_files = glob.glob( f"{BASE_PATH_BALLOON}/**/**.nc", recursive=True) - + # replace all \\ with / + all_ballon_files = [x.replace("\\", "/") for x in all_ballon_files] return all_ballon_files diff --git a/modules/tidi/__init__.py b/modules/tidi/__init__.py index 85cf094..631fd13 100644 --- a/modules/tidi/__init__.py +++ b/modules/tidi/__init__.py @@ -16,7 +16,8 @@ tidi_module = Blueprint("Tidi", __name__) def get_all_years(): res = glob.glob(f"{DATA_BASEPATH.tidi}/**/**.txt", recursive=True) # search for the folder name that is year - + # replace all \\ with / + res = [x.replace("\\", "/") for x in res] return { "path": res } diff --git a/run-linux.sh b/run-linux.sh new file mode 100644 index 0000000..6b7cea6 --- /dev/null +++ b/run-linux.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# 询问用户输入端口 +read -p "请输入端口号 (默认56800): " port + +# 验证端口输入,如果为空或非数字则使用默认值 +if [[ -z "$port" ]] || ! [[ "$port" =~ ^[0-9]+$ ]]; then + port=56800 +fi + +# 设置环境变量 +export Z_PORT=$port + +# 循环运行程序 +while true; do + ./linux/backend/backend + echo "程序退出,正在重启..." + sleep 1 +done diff --git a/run-windows.bat b/run-windows.bat new file mode 100644 index 0000000..685e2d3 --- /dev/null +++ b/run-windows.bat @@ -0,0 +1,24 @@ +@echo off + + +set /p "port=Input Port (Default 56800): " + + +set "numbers=0123456789" +if "%port%"=="" ( + set "port=56800" +) else ( + set "valid=true" + for /f "delims=%numbers%" %%i in ("%port%") do set "valid=false" + if not "%valid%"=="true" set "port=56800" +) + + +set Z_PORT=%port% + + +:loop +.\windows\backend\backend.exe +echo Exit, restart... +timeout /t 1 /nobreak >nul +goto loop