3 """The Tab Police watches for possibly inconsistent indentation."""
16 opts
, args
= getopt
.getopt(sys
.argv
[1:], "qv")
17 except getopt
.error
, msg
:
28 print "Usage:", sys
.argv
[0], "file_or_directory ..."
34 if os
.path
.isdir(file) and not os
.path
.islink(file):
36 print "%s: listing directory" % `
file`
37 names
= os
.listdir(file)
39 fullname
= os
.path
.join(file, name
)
40 if (os
.path
.isdir(fullname
) and
41 not os
.path
.islink(fullname
) or
42 os
.path
.normcase(name
[-3:]) == ".py"):
49 print "%s: I/O Error: %s" % (`
file`
, str(msg
))
53 print "checking", `
file`
, "with tabsize 8..."
57 tokenize
.tokenize(f
.readline
, tokens
.append
)
58 except tokenize
.TokenError
, msg
:
59 print "%s: Token Error: %s" % (`
file`
, str(msg
))
62 print "checking", `
file`
, "with tabsize 1..."
67 tokenize
.tokenize(f
.readline
, alttokens
.append
)
68 except tokenize
.TokenError
, msg
:
69 print "%s: Token Error: %s" % (`
file`
, str(msg
))
72 if tokens
== alttokens
:
74 print "%s: Clean bill of health." % `
file`
79 n
, altn
= len(tokens
), len(alttokens
)
80 for i
in range(max(n
, altn
)):
91 kind
, token
, start
, end
, line
= x
93 kind
, token
, start
, end
, line
= y
97 print "%s: *** Line %d: trouble in tab city! ***" % (
99 print "offending line:", `line`
101 print file, badline
, `line`
103 if __name__
== '__main__':