Factorize the definition of supported extensions

Signed-off-by: Michael Opdenacker <michael.opdenacker@bootlin.com>
This commit is contained in:
Michael Opdenacker 2019-10-08 07:33:36 +02:00
parent b205cda6db
commit 453e8a127c
3 changed files with 7 additions and 5 deletions

4
lib.py
View file

@ -180,3 +180,7 @@ def getDataDir ():
def currentProject ():
return os.path.basename (os.path.dirname (getDataDir ()))
def hasSupportedExt (filename):
ext = os.path.splitext(filename)[1]
return ext in ['.c', '.cc', '.cpp', '.h']

View file

@ -104,7 +104,7 @@ def query (cmd, *args):
path = args[1]
ext = os.path.splitext(path)[1]
if ext in ['.c', '.cc', '.cpp', '.h']:
if lib.hasSupportedExt (path):
buffer = BytesIO()
tokens = scriptLines ('tokenize-file', version, path)
even = True

View file

@ -74,8 +74,7 @@ def updateDefinitions (blobs):
hash = db.hash.get (blob)
filename = db.file.get (blob)
ext = os.path.splitext(filename)[1]
if ext not in ['.c', '.cc', '.cpp', '.h']: continue
if not lib.hasSupportedExt (filename): continue
lines = scriptLines ('parse-defs', hash, filename)
for l in lines:
@ -97,8 +96,7 @@ def updateReferences (blobs):
hash = db.hash.get (blob)
filename = db.file.get (blob)
ext = os.path.splitext(filename)[1]
if ext not in ['.c', '.cc', '.cpp', '.h']: continue
if not lib.hasSupportedExt (filename): continue
tokens = scriptLines ('tokenize-file', '-b', hash)
even = True