Created
January 23, 2013 07:47
-
-
Save tanelpuhu/4602912 to your computer and use it in GitHub Desktop.
reindent.py replaces tabs in litterals
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import sys | |
import os | |
if len(sys.argv) < 2: | |
print os.path.basename(sys.argv[0]), 'path' | |
sys.exit() | |
def handle_file(directory, file): | |
fullpath = os.path.join(directory, file) | |
with open(fullpath, 'r') as f: | |
faulty = [] | |
for num, row in enumerate(f.readlines()): | |
# lets ignore the comments | |
if row.strip()[:1] == '#': | |
continue | |
if row.expandtabs().strip() != row.strip(): | |
faulty.append((num, row)) | |
if faulty: | |
print fullpath | |
for num, row in faulty: | |
print '\t%s: %s' % (num, row.rstrip()) | |
for directory, subs, files in os.walk(sys.argv[1]): | |
if '.svn' in directory: | |
continue | |
for file in files: | |
if file.endswith('.py'): | |
handle_file(directory, file) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment