Update environment variable loading to allow overrides
- Modified load_dotenv() calls in multiple files to include override=True, ensuring that .env variables can replace existing environment variables. - Updated ota_storage.py to use default values for OTA upload directories, improving clarity and maintainability. - Enhanced get_ota_upload_dir() function to read environment variables dynamically, ensuring accurate directory paths based on the current environment.
This commit is contained in:
@@ -16,13 +16,9 @@ OTA_MODEL_X8 = "Luxsin-X8"
|
||||
OTA_MODEL_X9 = "Luxsin-X9"
|
||||
OTA_UPLOAD_MODELS = {OTA_MODEL_X8, OTA_MODEL_X9}
|
||||
|
||||
# 本地根目录;实际文件路径为 {根}/{md5前5位}/LUXSIN.PKG
|
||||
OTA_UPLOAD_DIR_DEV = os.getenv(
|
||||
"OTA_UPLOAD_DIR_DEV", "H:/soft/projects/luxsin/dashboard/ota"
|
||||
)
|
||||
OTA_UPLOAD_DIR_PROD = os.getenv(
|
||||
"OTA_UPLOAD_DIR_PROD", "/data/project/dashboard/upload"
|
||||
)
|
||||
# 默认本地根目录;实际路径为 {根}/{md5前5位}/LUXSIN.PKG(具体目录在 get_ota_upload_dir 内按当前环境读取)
|
||||
_OTA_UPLOAD_DIR_DEV_DEFAULT = "H:/soft/projects/luxsin/dashboard/ota"
|
||||
_OTA_UPLOAD_DIR_PROD_DEFAULT = "/data/project/dashboard/upload"
|
||||
|
||||
AWS_REGION = os.getenv("AWS_REGION", "eu-central-1")
|
||||
AWS_ACCESS_KEY_ID = os.getenv("AWS_ACCESS_KEY_ID", "")
|
||||
@@ -39,8 +35,12 @@ OTA_FILENAME_X9 = "LUXSIN.PKG"
|
||||
|
||||
|
||||
def get_ota_upload_dir() -> Path:
|
||||
is_dev = os.getenv("DEBUG", "False").lower() in ("true", "1", "yes")
|
||||
raw = OTA_UPLOAD_DIR_DEV if is_dev else OTA_UPLOAD_DIR_PROD
|
||||
"""按 DEBUG 选开发/生产目录;每次调用重新读环境变量,避免 import 早于 load_dotenv。"""
|
||||
debug_val = (os.getenv("DEBUG") or "false").strip().lower()
|
||||
is_dev = debug_val in ("true", "1", "yes", "on")
|
||||
dev = os.getenv("OTA_UPLOAD_DIR_DEV", _OTA_UPLOAD_DIR_DEV_DEFAULT)
|
||||
prod = os.getenv("OTA_UPLOAD_DIR_PROD", _OTA_UPLOAD_DIR_PROD_DEFAULT)
|
||||
raw = dev if is_dev else prod
|
||||
return Path(raw)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user