summaryrefslogtreecommitdiff
path: root/pyflakes/scripts/pyflakes.py
diff options
context:
space:
mode:
authorJonathan Lange <jml@canonical.com>2012-06-27 12:55:31 +0100
committerJonathan Lange <jml@canonical.com>2012-06-27 12:55:31 +0100
commite4b97e1033636f5844d2c1e06311b01ec2c247e5 (patch)
treebb65053077940273d650d885d58634e1cea00c52 /pyflakes/scripts/pyflakes.py
parenta2150f8e3675fd3478d4a62f540065e7664a093a (diff)
downloadpyflakes-e4b97e1033636f5844d2c1e06311b01ec2c247e5.tar.gz
Extract out thing to check files and directories recursively.
Diffstat (limited to 'pyflakes/scripts/pyflakes.py')
-rw-r--r--pyflakes/scripts/pyflakes.py29
1 files changed, 21 insertions, 8 deletions
diff --git a/pyflakes/scripts/pyflakes.py b/pyflakes/scripts/pyflakes.py
index 6b1dae2..abf9e2f 100644
--- a/pyflakes/scripts/pyflakes.py
+++ b/pyflakes/scripts/pyflakes.py
@@ -72,18 +72,31 @@ def checkPath(filename):
return 1
+def checkRecursive(paths):
+ """
+ Check the given files and look recursively under any directories, looking
+ for Python files and checking them, printing out any warnings detected.
+
+ @param paths: A list of file and directory names.
+ @return: the number of warnings printed
+ """
+ warnings = 0
+ for path in paths:
+ if os.path.isdir(path):
+ for dirpath, dirnames, filenames in os.walk(path):
+ for filename in filenames:
+ if filename.endswith('.py'):
+ warnings += checkPath(os.path.join(dirpath, filename))
+ else:
+ warnings += checkPath(path)
+ return warnings
+
+
def main():
warnings = 0
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'):
- warnings += checkPath(os.path.join(dirpath, filename))
- else:
- warnings += checkPath(arg)
+ warnings += checkRecursive(args)
else:
warnings += check(sys.stdin.read(), '<stdin>')