forked from chyrp/chyrp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsanitize.py
More file actions
27 lines (22 loc) · 752 Bytes
/
sanitize.py
File metadata and controls
27 lines (22 loc) · 752 Bytes
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
#!/usr/bin/python
from path import *
import re
def sanitize(filename):
"""
Walks the directory recursively and sanitizes filenames that match the given pattern.
"""
for f in path(".").walkfiles(filename):
source = f.text()
if re.search("[\t ]+\n", source):
print "/".join((f.parent, f.name)) + " has whitespace before a newline"
if re.search("[ ]+\t", source):
print "/".join((f.parent, f.name)) + " has tabs after spaces"
sanitized = re.sub("[\t ]+\n", "\n", source)
sanitized = re.sub("([ ]+)\t", "\\1 ", sanitized)
f.write_text(sanitized)
sanitize("*.php")
sanitize("*.rb")
sanitize("*.js")
sanitize("*.css")
sanitize("*.twig")
sanitize("triggers_list")