You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
953 B
31 lines
953 B
11 years ago
|
import os
|
||
|
import re
|
||
11 years ago
|
import codecs
|
||
11 years ago
|
|
||
11 years ago
|
class SourceScanner(object):
|
||
11 years ago
|
"""
|
||
|
Traverses directory tree, reads all source files, and passes their contents
|
||
|
to the Parser.
|
||
|
"""
|
||
|
|
||
|
def ScanDir(self, srcdir, parser):
|
||
|
"""
|
||
|
Scans provided path and passes all found contents to the parser using
|
||
|
parser.Parse method.
|
||
|
"""
|
||
11 years ago
|
extensions = tuple(parser.GetSupportedExtensions())
|
||
11 years ago
|
for dirname, dirnames, filenames in os.walk(srcdir):
|
||
|
for filename in filenames:
|
||
11 years ago
|
if filename.endswith(extensions):
|
||
11 years ago
|
path = os.path.join(dirname, filename)
|
||
|
self.ScanFile(path, parser)
|
||
|
|
||
|
def ScanFile(self, path, parser):
|
||
|
"""
|
||
|
Scans provided file and passes its contents to the parser using
|
||
|
parser.Parse method.
|
||
|
"""
|
||
11 years ago
|
with codecs.open(path, 'r', 'utf-8') as f:
|
||
11 years ago
|
contents = f.read()
|
||
|
parser.Parse(contents)
|