优化WORKING_DIR处理:1) 提取get_working_dir辅助函数 2) 确保所有地方统一使用默认值 3) 避免重复代码
This commit is contained in:
@@ -19,14 +19,19 @@ def get_file_hash(file_path):
|
|||||||
return hash_md5.hexdigest()
|
return hash_md5.hexdigest()
|
||||||
|
|
||||||
|
|
||||||
def get_working_files():
|
def get_working_dir():
|
||||||
"""从环境变量WORKING_FILES获取要打包的文件列表"""
|
"""获取工作目录,处理默认值和路径转换"""
|
||||||
working_files_env = os.environ.get('WORKING_FILES', '')
|
|
||||||
working_dir = os.environ.get('WORKING_DIR', '.')
|
working_dir = os.environ.get('WORKING_DIR', '.')
|
||||||
|
|
||||||
# 确保WORKING_DIR是绝对路径
|
# 确保WORKING_DIR是绝对路径
|
||||||
if not os.path.isabs(working_dir):
|
if not os.path.isabs(working_dir):
|
||||||
working_dir = os.path.abspath(working_dir)
|
working_dir = os.path.abspath(working_dir)
|
||||||
|
return working_dir
|
||||||
|
|
||||||
|
|
||||||
|
def get_working_files():
|
||||||
|
"""从环境变量WORKING_FILES获取要打包的文件列表"""
|
||||||
|
working_files_env = os.environ.get('WORKING_FILES', '')
|
||||||
|
working_dir = get_working_dir()
|
||||||
|
|
||||||
if not working_files_env:
|
if not working_files_env:
|
||||||
return []
|
return []
|
||||||
@@ -224,9 +229,7 @@ def upload_working_files(password=None):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# 获取WORKING_DIR
|
# 获取WORKING_DIR
|
||||||
working_dir = os.environ.get('WORKING_DIR', '.')
|
working_dir = get_working_dir()
|
||||||
if not os.path.isabs(working_dir):
|
|
||||||
working_dir = os.path.abspath(working_dir)
|
|
||||||
|
|
||||||
# 打包文件
|
# 打包文件
|
||||||
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
||||||
@@ -241,9 +244,7 @@ def upload_working_files(password=None):
|
|||||||
os.unlink(zip_path)
|
os.unlink(zip_path)
|
||||||
|
|
||||||
# 获取WORKING_DIR
|
# 获取WORKING_DIR
|
||||||
working_dir = os.environ.get('WORKING_DIR', '.')
|
working_dir = get_working_dir()
|
||||||
if not os.path.isabs(working_dir):
|
|
||||||
working_dir = os.path.abspath(working_dir)
|
|
||||||
|
|
||||||
# 使用内置的zipfile模块创建加密ZIP
|
# 使用内置的zipfile模块创建加密ZIP
|
||||||
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED, compresslevel=9) as zipf:
|
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED, compresslevel=9) as zipf:
|
||||||
|
|||||||
Reference in New Issue
Block a user