refactor: 图片迁移脚本
All checks were successful
Gitea Actions Official-website / deploy-dev (push) Successful in 3s

This commit is contained in:
2025-12-31 14:58:48 +08:00
parent 2ca25e083e
commit 69c3634731

View File

@@ -672,13 +672,18 @@ def create_example_config(config_file: str):
def read_image_paths(image_list_file: str) -> List[str]: def read_image_paths(image_list_file: str) -> List[str]:
"""从文件读取图片路径列表""" """从文件读取图片路径列表"""
paths = [] paths = []
not_images = []
try: try:
with open(image_list_file, "r", encoding="utf-8") as f: with open(image_list_file, "r", encoding="utf-8") as f:
for line in f: for line in f:
line = line.strip() line = line.strip()
if line and not line.startswith("#"): if line and not line.startswith("#"):
paths.append(line) if not line.endswith((".png", ".jpeg", ".jpg", ".gif", ".webp")):
print(f"从文件读取 {len(paths)} 个图片路径") not_images.append(line)
else:
paths.append(line)
print(f"从文件中读取到 {len(paths)} 个图片路径数据行")
print(f"从文件中读取到 {len(not_images)} 个非图片路径数据行")
except Exception as e: except Exception as e:
print(f"读取图片路径文件失败 {image_list_file}: {e}") print(f"读取图片路径文件失败 {image_list_file}: {e}")
return paths return paths
@@ -889,9 +894,14 @@ def main():
print("请使用 --input 指定文件或直接在命令行提供路径") print("请使用 --input 指定文件或直接在命令行提供路径")
sys.exit(1) sys.exit(1)
origin_paths = image_paths
# 去重 # 去重
image_paths = list(set(image_paths)) image_paths = list(set(image_paths))
repeats = len(origin_paths) - len(image_paths)
if repeats > 0:
print(f"从文件中读取到 {repeats} 个重复图片路径数据行")
# 创建并运行迁移器 # 创建并运行迁移器
migrator = ImageMigrator( migrator = ImageMigrator(
source_config=source_config, source_config=source_config,