mirror of
https://github.com/PX4/PX4-Autopilot.git
synced 2026-05-31 18:47:21 +08:00
Simplify file extension check.
This commit is contained in:
@@ -8,20 +8,15 @@ class Scanner(object):
|
|||||||
to the Parser.
|
to the Parser.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
re_file_extension = re.compile(r'\.([^\.]+)$')
|
|
||||||
|
|
||||||
def ScanDir(self, srcdir, parser):
|
def ScanDir(self, srcdir, parser):
|
||||||
"""
|
"""
|
||||||
Scans provided path and passes all found contents to the parser using
|
Scans provided path and passes all found contents to the parser using
|
||||||
parser.Parse method.
|
parser.Parse method.
|
||||||
"""
|
"""
|
||||||
extensions = set(parser.GetSupportedExtensions())
|
extensions = tuple(parser.GetSupportedExtensions())
|
||||||
for dirname, dirnames, filenames in os.walk(srcdir):
|
for dirname, dirnames, filenames in os.walk(srcdir):
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
m = self.re_file_extension.search(filename)
|
if filename.endswith(extensions):
|
||||||
if m:
|
|
||||||
ext = m.group(1)
|
|
||||||
if ext in extensions:
|
|
||||||
path = os.path.join(dirname, filename)
|
path = os.path.join(dirname, filename)
|
||||||
self.ScanFile(path, parser)
|
self.ScanFile(path, parser)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user