forked from ZeroPointSix/outlookEmailPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfix_format.py
More file actions
50 lines (39 loc) · 1.29 KB
/
Copy pathfix_format.py
File metadata and controls
50 lines (39 loc) · 1.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import re
from pathlib import Path
def fix_file(filepath):
with open(filepath, "r", encoding="utf-8") as f:
content = f.read()
original = content
# 修复 conn.execute(\n """\n -> conn.execute("""
content = re.sub(r'(\.execute|\.executemany|cursor\.execute)\(\s*\n\s*(""")', r"\1(\2", content)
# 修复 """\n) -> """)
content = re.sub(r'(""")\s*\n\s*\)', r"\1)", content)
# 修复不必要的括号: var = (\n expr\n)
content = re.sub(r"(\w+)\s*=\s*\(\s*\n\s*([^\n]+)\s*\n\s*\)", r"\1 = \2", content)
if content != original:
with open(filepath, "w", encoding="utf-8") as f:
f.write(content)
return True
return False
files = [
"outlook_web/controllers/scheduler.py",
"outlook_web/controllers/system.py",
"outlook_web/repositories/groups.py",
"outlook_web/db.py",
"outlook_web/repositories/accounts.py",
"start.py",
"outlook_web/services/scheduler.py",
"outlook_web/controllers/accounts.py",
"outlook_web/services/refresh.py",
]
modified = 0
for f in files:
if Path(f).exists():
if fix_file(f):
print(f"✓ {f}")
modified += 1
else:
print(f"- {f}")
else:
print(f"✗ {f} 不存在")
print(f"\n修改了 {modified} 个文件")