Skip to content

Instantly share code, notes, and snippets.

@tanelpuhu
Created January 23, 2013 07:47
Show Gist options
  • Save tanelpuhu/4602912 to your computer and use it in GitHub Desktop.
Save tanelpuhu/4602912 to your computer and use it in GitHub Desktop.
reindent.py replaces tabs in litterals
#!/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