From d1bf4c42df3834ccff6234e123c0cf268d492332 Mon Sep 17 00:00:00 2001 From: vit9696 Date: Wed, 26 Feb 2020 06:34:06 +0300 Subject: [PATCH] OcConfigurationLib: Add CheckSchema.py utility --- Library/OcConfigurationLib/CheckSchema.py | 27 +++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100755 Library/OcConfigurationLib/CheckSchema.py diff --git a/Library/OcConfigurationLib/CheckSchema.py b/Library/OcConfigurationLib/CheckSchema.py new file mode 100755 index 00000000..88592b78 --- /dev/null +++ b/Library/OcConfigurationLib/CheckSchema.py @@ -0,0 +1,27 @@ +#!/usr/bin/env python3 + +""" +Validates schema files (e.g. OcConfigurationLib.c) for being sorted. +""" + +import re +import sys + +if len(sys.argv) < 2: + print('Pass file to check') + sys.exit(-1) + +with open(sys.argv[1], 'r') as f: + prev = '' + content = [l.strip() for l in f.readlines()] + for i, l in enumerate(content): + if l == 'OC_SCHEMA': + print('Checking schema {}'.format(re.match('^\w+', content[i+1])[0])) + prev = '' + continue + x = re.search('"([^"]+)"', l) + if x: + if x[1] < prev: + print('ERROR: {} succeeds {}'.format(prev, x[1])) + sys.exit(1) + prev = x[1]