misra.py: Add error handling when there are missing files, wrong arguments, etc

This commit is contained in:
Daniel Marjamäki 2018-02-17 07:39:37 +01:00
parent 78cceea8f6
commit 7f616a1805
1 changed files with 16 additions and 2 deletions

View File

@ -1053,10 +1053,17 @@ def loadRuleTexts(filename):
continue
def loadRuleTextsFromPdf(filename):
if not os.path.isfile(filename):
print('Fatal error: PDF file is not found: ' + filename)
sys.exit(1)
f = tempfile.NamedTemporaryFile(delete=False)
f.close()
#print('tempfile:' + f.name)
try:
subprocess.call(['pdftotext', filename, f.name])
except OSError as err:
print('Fatal error: Failed to execute pdftotext: ' + str(err))
sys.exit(1)
loadRuleTexts(f.name)
try:
os.remove(f.name)
@ -1105,9 +1112,16 @@ for arg in sys.argv[1:]:
if arg == '-verify':
VERIFY = True
elif arg.startswith('--rule-texts='):
loadRuleTexts(arg[13:])
filename = arg[13:]
if not os.path.isfile(filename):
print('Fatal error: file is not found: ' + filename)
sys.exit(1)
loadRuleTexts(filename)
elif arg.startswith('--misra-pdf='):
loadRuleTextsFromPdf(arg[12:])
else:
print('Fatal error: unhandled argument ' + arg)
sys.exit(1)
for arg in sys.argv[1:]:
if not arg.endswith('.dump'):