px4-firmware/Tools/px4params/srcscanner.py

31 lines
953 B
Python
Raw Normal View History

2013-10-17 20:47:15 -03:00
import os
import re
2014-02-15 20:47:11 -04:00
import codecs
2013-10-17 20:47:15 -03:00
class SourceScanner(object):
2013-10-17 20:47:15 -03:00
"""
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.
"""
2014-02-18 17:00:10 -04:00
extensions = tuple(parser.GetSupportedExtensions())
2013-10-17 20:47:15 -03:00
for dirname, dirnames, filenames in os.walk(srcdir):
for filename in filenames:
2014-02-18 17:00:10 -04:00
if filename.endswith(extensions):
2013-10-17 20:47:15 -03:00
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.
"""
2014-02-15 20:47:11 -04:00
with codecs.open(path, 'r', 'utf-8') as f:
2013-10-17 20:47:15 -03:00
contents = f.read()
parser.Parse(contents)