Fix update_schemas script
Script update_schemas.py was incorrectly generating schemas since change
f395daac96c8122623700c2b124d905266ea8223. This was caused by treating
'edm' as 'edmx' during parse process.
Additionally, glob pattern was incorrectly skipping all files starting
with letter 'O', instead of 'Oem' phrase. This lead to python exceptions
during generation, as the script was trying to recreate existing
directories like 'OperatingConfig'.
Unused imports were removed.
Tested:
- running update_schemas.py no longer generates malformed data and no
exception were thrown.
- all files generated by update_schemas.py are generated identically as
before regression.
Signed-off-by: Szymon Dompke <szymon.dompke@intel.com>
Change-Id: I5e2025ec8b264a38cbf5bb944142c83c0486ce50
diff --git a/scripts/update_schemas.py b/scripts/update_schemas.py
index 3ce4173..dd39278 100755
--- a/scripts/update_schemas.py
+++ b/scripts/update_schemas.py
@@ -3,12 +3,9 @@
import zipfile
from io import BytesIO
import os
-from collections import defaultdict
from collections import OrderedDict
-from distutils.version import StrictVersion
import shutil
import json
-import glob
import xml.etree.ElementTree as ET
@@ -134,12 +131,15 @@
zip_ref = zipfile.ZipFile(zipBytesIO)
# Remove the old files
+skip_prefixes = ('Oem')
if os.path.exists(schema_path):
- files = glob.glob(os.path.join(schema_path, '[!Oem]*'))
+ files = [os.path.join(schema_path, f) for f in os.listdir(schema_path)
+ if not f.startswith(skip_prefixes)]
for f in files:
os.remove(f)
if os.path.exists(json_schema_path):
- files = glob.glob(os.path.join(json_schema_path, '[!Oem]*'))
+ files = [os.path.join(json_schema_path, f) for f in
+ os.listdir(json_schema_path) if not f.startswith(skip_prefixes)]
for f in files:
if (os.path.isfile(f)):
os.remove(f)
@@ -183,10 +183,11 @@
content = content.replace(b'\r\n', b'\n')
xml_root = ET.fromstring(content)
edmx = "{http://docs.oasis-open.org/odata/ns/edmx}"
+ edm = "{http://docs.oasis-open.org/odata/ns/edm}"
for edmx_child in xml_root:
if edmx_child.tag == edmx + "DataServices":
for data_child in edmx_child:
- if data_child.tag == edmx + "Schema":
+ if data_child.tag == edm + "Schema":
namespace = data_child.attrib["Namespace"]
if namespace.startswith("RedfishExtensions"):
metadata_index.write(