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 23 lines (18 sloc) 0.615 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from path import *
import re
 
def walk(filename):
    """docstring for walk"""
    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)
 
walk("*.php")
walk("*.rb")
walk("*.js")
walk("*.twig")
walk("triggers_list")