refactor: 图片迁移python脚本
Some checks failed
Gitea Actions Official-website / deploy-dev (push) Failing after 3s

This commit is contained in:
2025-12-22 10:09:35 +08:00
parent c49c3b40d8
commit 33929b8284
3 changed files with 34 additions and 6 deletions

View File

@@ -316,9 +316,9 @@ class ImageMigrator:
print(
f"DEBUG ensure_target_directory: 目录实际上已存在: {current_path}"
)
except:
except Exception as listdir_e:
# 目录确实不存在且创建失败
print(f"错误: 无法创建目录 {current_path}: {mkdir_e}")
print(f"错误: 无法创建目录 {current_path}: {listdir_e}")
return False
# 最终确认目录是否创建成功
@@ -365,7 +365,7 @@ class ImageMigrator:
return True, os.path.getsize(source_path)
else:
if self.verbose:
print(f"DEBUG: 文件不存在!")
print("DEBUG: 文件不存在!")
return False, 0
else:
# SSH远程文件
@@ -388,7 +388,7 @@ class ImageMigrator:
if self.source_config.is_local():
# 从本地文件复制
if self.verbose:
print(f"DEBUG read_source_file: 开始复制文件")
print("DEBUG read_source_file: 开始复制文件")
print(f"DEBUG read_source_file: 源路径: {source_path}")
print(f"DEBUG read_source_file: 临时路径: {temp_path}")
print(
@@ -401,7 +401,7 @@ class ImageMigrator:
shutil.copy2(source_path, temp_path)
if self.verbose:
print(f"DEBUG read_source_file: 复制完成")
print("DEBUG read_source_file: 复制完成")
print(
f"DEBUG read_source_file: 临时文件是否存在: {os.path.exists(temp_path)}"
)
@@ -417,6 +417,8 @@ class ImageMigrator:
return True
except Exception as e:
with open("fails.txt", "a", encoding="utf-8") as file:
file.write(f"{source_path}\n")
print(f"读取源文件失败 {source_path}: {e}")
import traceback
@@ -519,7 +521,7 @@ class ImageMigrator:
self.target_sftp.put(temp_path, target_path)
if self.verbose:
print(f"DEBUG: 上传完成")
print("DEBUG: 上传完成")
except Exception as e:
if self.verbose: