2008-11-05 01:03:06 +00:00
|
|
|
#!/usr/bin/env python
|
2007-11-06 04:32:08 +00:00
|
|
|
|
2019-03-22 10:40:58 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2009-06-29 22:46:58 +00:00
|
|
|
import os, sys
|
2007-11-06 04:32:08 +00:00
|
|
|
|
|
|
|
from twisted.python import usage
|
|
|
|
|
|
|
|
class Options(usage.Options):
|
|
|
|
optFlags = [
|
|
|
|
("recursive", "r", "Search for .py files recursively"),
|
|
|
|
]
|
|
|
|
def parseArgs(self, *starting_points):
|
|
|
|
self.starting_points = starting_points
|
|
|
|
|
2009-06-29 22:46:58 +00:00
|
|
|
found = [False]
|
|
|
|
|
2007-11-06 04:32:08 +00:00
|
|
|
def check(fn):
|
|
|
|
f = open(fn, "r")
|
|
|
|
for i,line in enumerate(f.readlines()):
|
|
|
|
if line == "\n":
|
|
|
|
continue
|
|
|
|
if line[-1] == "\n":
|
|
|
|
line = line[:-1]
|
|
|
|
if line.rstrip() != line:
|
|
|
|
# the %s:%d:%d: lets emacs' compile-mode jump to those locations
|
2019-03-22 10:40:58 +00:00
|
|
|
print("%s:%d:%d: trailing whitespace" % (fn, i+1, len(line)+1))
|
2009-06-29 22:46:58 +00:00
|
|
|
found[0] = True
|
2007-11-06 04:32:08 +00:00
|
|
|
f.close()
|
|
|
|
|
|
|
|
o = Options()
|
|
|
|
o.parseOptions()
|
|
|
|
if o['recursive']:
|
|
|
|
for starting_point in o.starting_points:
|
|
|
|
for root, dirs, files in os.walk(starting_point):
|
|
|
|
for fn in [f for f in files if f.endswith(".py")]:
|
|
|
|
fn = os.path.join(root, fn)
|
|
|
|
check(fn)
|
|
|
|
else:
|
|
|
|
for fn in o.starting_points:
|
|
|
|
check(fn)
|
2009-06-29 22:46:58 +00:00
|
|
|
if found[0]:
|
|
|
|
sys.exit(1)
|
|
|
|
sys.exit(0)
|