vito / chyrp

The ultra-lightweight ultra-flexible blogging engine with a fetish for birds and misspellings.

This URL has Read+Write access

chyrp / sanitize.py
100644 26 lines (21 sloc) 0.734 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
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")