~ubuntu-branches/ubuntu/maverick/pyflakes/maverick

« back to all changes in this revision

Viewing changes to bin/.svn/text-base/pyflakes.svn-base

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2005-10-13 02:37:05 UTC
  • Revision ID: james.westby@ubuntu.com-20051013023705-wec3rwsqaq34d6ai
Tags: upstream-0.2.1
ImportĀ upstreamĀ versionĀ 0.2.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
import compiler, sys
 
4
import os
 
5
import pyflakes
 
6
 
 
7
 
 
8
def check(codeString, filename):
 
9
    try:
 
10
        tree = compiler.parse(codeString)
 
11
    except (SyntaxError, IndentationError):
 
12
        value = sys.exc_info()[1]
 
13
        (lineno, offset, line) = value[1][1:]
 
14
        if line.endswith("\n"):
 
15
            line = line[:-1]
 
16
        print >> sys.stderr, 'could not compile %r:%d:' % (filename, lineno)
 
17
        print >> sys.stderr, line
 
18
        print >> sys.stderr, " " * (offset-2), "^"
 
19
    else:
 
20
        w = pyflakes.Checker(tree, filename)
 
21
        w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
 
22
        for warning in w.messages:
 
23
            print warning
 
24
 
 
25
 
 
26
def checkPath(filename):
 
27
    return check(file(filename).read(), filename)
 
28
 
 
29
args = sys.argv[1:]
 
30
if args:
 
31
    for arg in args:
 
32
        if os.path.isdir(arg):
 
33
            for dirpath, dirnames, filenames in os.walk(arg):
 
34
                for filename in filenames:
 
35
                    if filename.endswith('.py'):
 
36
                        checkPath(os.path.join(dirpath, filename))
 
37
        else:
 
38
            checkPath(arg)
 
39
else:
 
40
    check(sys.stdin.read(), '<stdin>')