diff options
author | moe <moe> | 2005-10-03 20:51:28 +0000 |
---|---|---|
committer | moe <moe> | 2005-10-03 20:51:28 +0000 |
commit | 4fa714a29686be4f31845d5f31a79efa0e692662 (patch) | |
tree | 12ce3f2f1aa1d28959c77374d19c57b96257c057 /bin | |
download | pyflakes-4fa714a29686be4f31845d5f31a79efa0e692662.tar.gz |
copy svn/Pyflakes/trunk -> svn/Divmod/trunk/Pyflakes
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/pyflakes | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/bin/pyflakes b/bin/pyflakes new file mode 100755 index 0000000..009bcf8 --- /dev/null +++ b/bin/pyflakes @@ -0,0 +1,40 @@ +#!/usr/bin/python + +import compiler, sys +import os +import pyflakes + + +def check(codeString, filename): + try: + tree = compiler.parse(codeString) + except (SyntaxError, IndentationError): + value = sys.exc_info()[1] + (lineno, offset, line) = value[1][1:] + if line.endswith("\n"): + line = line[:-1] + print >> sys.stderr, 'could not compile %r:%d:' % (filename, lineno) + print >> sys.stderr, line + print >> sys.stderr, " " * (offset-2), "^" + else: + w = pyflakes.Checker(tree, filename) + w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno)) + for warning in w.messages: + print warning + + +def checkPath(filename): + return check(file(filename).read(), filename) + +args = sys.argv[1:] +if args: + for arg in args: + if os.path.isdir(arg): + for dirpath, dirnames, filenames in os.walk(arg): + for filename in filenames: + if filename.endswith('.py'): + checkPath(os.path.join(dirpath, filename)) + else: + checkPath(arg) +else: + check(sys.stdin.read(), '<stdin>') |