forked from rafalp/Misago
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pycodestyle.py
38 lines (27 loc) · 975 Bytes
/
pycodestyle.py
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
"""
Code style cleanups done after yapf
"""
import argparse
import codecs
import os
from extras import fixdictsformatting
CLEANUPS = [
fixdictsformatting,
]
def walk_directory(root, dirs, files):
for filename in files:
if filename.lower().endswith('.py'):
with codecs.open(os.path.join(root, filename), 'r', 'utf-8') as f:
filesource = f.read()
org_source = filesource
for cleanup in CLEANUPS:
filesource = cleanup.fix_formatting(filesource)
if org_source != filesource:
print 'afterclean: %s' % os.path.join(root, filename)
with codecs.open(os.path.join(root, filename), 'w', 'utf-8') as f:
f.write(filesource)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('path', nargs='?', default='./')
for args in os.walk(parser.parse_args().path):
walk_directory(*args)