【打包】增加日志

main
刘涛 2025-07-25 16:55:47 +08:00
parent 80fa084237
commit 41e481e4dc
1 changed files with 12 additions and 1 deletions

View File

@ -150,6 +150,8 @@ def CopyAssets(srcAssetPath, targetAssetPath):
except OSError as e:
print(f"Error: Failed to create directory '{targetAssetPath}': {e}")
sys.exit(12)
print(f"Start copying assets from '{srcAssetPath}' to '{targetAssetPath}'")
# 遍历srcAssetPath下的所有文件和文件夹
try:
@ -158,20 +160,29 @@ def CopyAssets(srcAssetPath, targetAssetPath):
target_item_path = os.path.join(targetAssetPath, item)
# 如果是文件,则复制
if os.path.isfile(src_item_path):
# 检查目标文件是否已存在,如果存在则输出警告
if os.path.exists(target_item_path):
print(f"Warning: Target file '{target_item_path}' already exists and will be overwritten.")
try:
with open(src_item_path, 'rb') as src_file:
with open(target_item_path, 'wb') as target_file:
target_file.write(src_file.read())
print(f"Copied file: {src_item_path} to {target_item_path}")
# print(f"Copied file: {src_item_path} to {target_item_path}")
except IOError as e:
print(f"Error: Failed to copy file '{src_item_path}': {e}")
sys.exit(13)
# 如果是文件夹,则递归调用CopyAssets
elif os.path.isdir(src_item_path):
# 检查目标目录是否已存在,如果存在则输出警告
if os.path.exists(target_item_path):
print(f"Warning: Target directory '{target_item_path}' already exists, merging contents.")
CopyAssets(src_item_path, target_item_path)
except OSError as e:
print(f"Error: Failed to list directory '{srcAssetPath}': {e}")
sys.exit(14)
print(f"Assets copied successfully from '{srcAssetPath}' to '{targetAssetPath}'")
if __name__ == "__main__":
main()