Files
douyin_guaji-main/tools/cleanup/fix_trailing_whitespace.py
T
CodexandClaude Opus 4.5 a19fa35a0f chore: 整理 tools/ 47 个脚本按功能分组
- diagnostics/ 11 个:环境/配置/依赖诊断
- logs/ 7 个:日志分析与查看
- coords/ 6 个:坐标拾取与区域选择
- cleanup/ 3 个:代码清理工具
- adb/ 2 个:ADB / 输入法相关
- windows/ 4 个:Windows 系统修复(备份)
- dev/ 9 个:开发辅助 / 运行时探测

并更新 tools/README.md 描述新结构。
删除 3 个明显的临时调试脚本 (_dump_lines.py / tmp_*.py)。

tools/ 不被业务代码 import,分组仅为人工浏览方便。

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
2026-05-20 23:25:28 +08:00

47 lines
1.6 KiB
Python

#!/usr/bin/env python3
"""批量移除 Python 文件尾随空白并确保文件以单一换行结束。"""
import os
import io
def should_skip(path):
parts = path.split(os.sep)
return any(p.startswith('.') or p == '__pycache__' or p == '.venv' for p in parts)
root = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))
count = 0
changed_files = []
for dirpath, dirnames, filenames in os.walk(root):
# skip venv and hidden dirs
if should_skip(dirpath):
continue
for fname in filenames:
if not fname.endswith('.py'):
continue
fpath = os.path.join(dirpath, fname)
if should_skip(fpath):
continue
try:
with io.open(fpath, 'r', encoding='utf-8') as f:
lines = f.readlines()
except Exception:
continue
new_lines = [line.rstrip() + '\n' for line in lines]
# remove extra final newlines: ensure exactly one final newline
if new_lines:
# strip trailing empty lines
while len(new_lines) > 1 and new_lines[-1].strip() == '':
new_lines.pop()
if not new_lines[-1].endswith('\n'):
new_lines[-1] = new_lines[-1] + '\n'
new_text = ''.join(new_lines)
old_text = ''.join(lines)
if new_text != old_text:
with io.open(fpath, 'w', encoding='utf-8', newline='\n') as f:
f.write(new_text)
changed_files.append(fpath)
count += 1
print(f"Processed {count} files; modified: {len(changed_files)}")
for p in changed_files:
print(p)