Commit 27ba62f0 authored by canterburym's avatar canterburym
Browse files

Fixing linter / parser to deal with 33108

parent c43e765a
Pipeline #2590 passed with stages
in 55 seconds
......@@ -117,6 +117,9 @@ def D34(t, context):
errors = []
for m in t['members']:
logging.debug (f" D34 checking member {m}")
if not m:
logging.debug (" (appears to be None, ignoring)")
continue
badLetters = list(set([letter for letter in m['name'] if not ((letter in string.ascii_letters) or (letter in string.digits)) ]))
if len(badLetters) > 0:
appendFailure (errors, context, { "field" : m['name'],
......@@ -130,6 +133,8 @@ def D34(t, context):
def D43 (t, context):
errors = []
if (t['type'] == 'SEQUENCE') or (t['type'] == 'CHOICE'):
if not 'tag' in t['members'][0]:
return errors
if t['members'][0]['tag']['number'] != 1:
appendFailure (errors, context, {"message" : f"Tag numbers for {context['type']} start at {t['members'][0]['tag']['number']}, not 1"})
return errors
......@@ -155,17 +160,15 @@ def checkD45 (t, context):
return []
errors = []
for m in t['members']:
if not m: continue
if m['type'] in ['ENUMERATED','SEQUENCE','CHOICE', 'SET']:
appendFailure(errors, context, { "field" : m['name'],
"message" : f"Field '{m['name']}' in {context['type']} is an anonymous {m['type']}"})
return errors
def lintASN1File (asnFile):
print (f"File: {asnFile}")
errors = []
context = {'file' : asnFile}
try:
......@@ -199,15 +202,23 @@ def lintASN1Files (fileList):
errorMap = {}
logging.info("Checking files...")
for f in fileList:
errorMap[f] = lintASN1File(f)
errorMap[str(f)] = lintASN1File(str(f))
return errorMap
ignoreReleases = {'33108' : [f'r{i}' for i in range(5, 17)],
'33128' : [] }
def lintAllASN1FilesInPath (path):
globPattern = str(Path(path)) + '/*.asn1'
logging.info("Searching: " + globPattern)
schemaGlob = glob(globPattern, recursive=True)
return lintASN1Files(schemaGlob)
fileList = list(Path(path).rglob("*.asn1")) + list(Path(path).rglob("*.asn"))
ignoredFiles = [file for file in fileList if file.parts[1] in ignoreReleases[file.parts[0]]]
logging.info(f"Ignoring {len(ignoredFiles)} files")
logging.debug(ignoredFiles)
fileList = [file for file in fileList if file not in ignoredFiles]
return lintASN1Files(fileList)
if __name__ == '__main__':
result = lintAllASN1FilesInPath("./")
......
......@@ -5,8 +5,18 @@ from pathlib import Path
from pprint import pprint
ignoreReleases = {'33108' : [f'r{i}' for i in range(5, 16)],
'33128' : [] }
if __name__ == '__main__':
fileList = list(Path(".").rglob("*.asn1")) + list(Path(".").rglob("*.asn"))
ignoredFiles = [file for file in fileList if file.parts[1] in ignoreReleases[file.parts[0]]]
logging.info(f"Ignoring {len(ignoredFiles)} files")
logging.debug(ignoredFiles)
fileList = [file for file in fileList if file not in ignoredFiles]
if len(fileList) == 0:
logging.warning ("No files specified")
exit(0)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment