From 7c37a936b82db6e440cb510963fc8d8c8abd1d4f Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Wed, 8 Feb 2023 15:04:25 -0600 Subject: [PATCH] Fix small differences Signed-off-by: Michael Carroll --- sdf/1.10/CMakeLists.txt | 2 +- sdf/1.5/CMakeLists.txt | 2 +- sdf/1.6/CMakeLists.txt | 2 +- sdf/1.7/CMakeLists.txt | 2 +- sdf/1.8/CMakeLists.txt | 2 +- sdf/1.9/CMakeLists.txt | 2 +- tools/xmlschema.py | 64 +++++++++++++++++++++++++---------------- 7 files changed, 46 insertions(+), 30 deletions(-) diff --git a/sdf/1.10/CMakeLists.txt b/sdf/1.10/CMakeLists.txt index 29fa760b4..55a906f71 100644 --- a/sdf/1.10/CMakeLists.txt +++ b/sdf/1.10/CMakeLists.txt @@ -73,7 +73,7 @@ foreach(FIL ${sdfs}) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.xsd" - COMMAND ${RUBY} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py + COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py ARGS --sdf-dir ${CMAKE_CURRENT_SOURCE_DIR} --input-file ${ABS_FIL} --output-dir ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${ABS_FIL} COMMENT "Running xml schema compiler on ${FIL}" diff --git a/sdf/1.5/CMakeLists.txt b/sdf/1.5/CMakeLists.txt index a1b381fb8..68ceba50f 100644 --- a/sdf/1.5/CMakeLists.txt +++ b/sdf/1.5/CMakeLists.txt @@ -67,7 +67,7 @@ foreach(FIL ${sdfs}) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.xsd" - COMMAND ${RUBY} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py + COMMAND ${Pyhton3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py ARGS --sdf-dir ${CMAKE_CURRENT_SOURCE_DIR} --input-file ${ABS_FIL} --output-dir ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${ABS_FIL} COMMENT "Running xml schema compiler on ${FIL}" diff --git a/sdf/1.6/CMakeLists.txt b/sdf/1.6/CMakeLists.txt index efd92f07f..ed41bf3b1 100644 --- a/sdf/1.6/CMakeLists.txt +++ b/sdf/1.6/CMakeLists.txt @@ -71,7 +71,7 @@ foreach(FIL ${sdfs}) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.xsd" - COMMAND ${RUBY} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py + COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py ARGS --sdf-dir ${CMAKE_CURRENT_SOURCE_DIR} --input-file ${ABS_FIL} --output-dir ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${ABS_FIL} COMMENT "Running xml schema compiler on ${FIL}" diff --git a/sdf/1.7/CMakeLists.txt b/sdf/1.7/CMakeLists.txt index 6b32198f0..51e6fe9af 100644 --- a/sdf/1.7/CMakeLists.txt +++ b/sdf/1.7/CMakeLists.txt @@ -72,7 +72,7 @@ foreach(FIL ${sdfs}) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.xsd" - COMMAND ${RUBY} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py + COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py ARGS --sdf-dir ${CMAKE_CURRENT_SOURCE_DIR} --input-file ${ABS_FIL} --output-dir ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${ABS_FIL} COMMENT "Running xml schema compiler on ${FIL}" diff --git a/sdf/1.8/CMakeLists.txt b/sdf/1.8/CMakeLists.txt index bdd8edb33..ed7f874df 100644 --- a/sdf/1.8/CMakeLists.txt +++ b/sdf/1.8/CMakeLists.txt @@ -74,7 +74,7 @@ foreach(FIL ${sdfs}) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.xsd" - COMMAND ${RUBY} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py + COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py ARGS --sdf-dir ${CMAKE_CURRENT_SOURCE_DIR} --input-file ${ABS_FIL} --output-dir ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${ABS_FIL} COMMENT "Running xml schema compiler on ${FIL}" diff --git a/sdf/1.9/CMakeLists.txt b/sdf/1.9/CMakeLists.txt index bef0c8a5c..193f82c23 100644 --- a/sdf/1.9/CMakeLists.txt +++ b/sdf/1.9/CMakeLists.txt @@ -74,7 +74,7 @@ foreach(FIL ${sdfs}) add_custom_command( OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.xsd" - COMMAND ${RUBY} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py + COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py ARGS --sdf-dir ${CMAKE_CURRENT_SOURCE_DIR} --input-file ${ABS_FIL} --output-dir ${CMAKE_CURRENT_BINARY_DIR} DEPENDS ${ABS_FIL} COMMENT "Running xml schema compiler on ${FIL}" diff --git a/tools/xmlschema.py b/tools/xmlschema.py index ee9ebf3f0..26746c8c7 100644 --- a/tools/xmlschema.py +++ b/tools/xmlschema.py @@ -27,6 +27,7 @@ class XmlSchema: '1': ('1', '1'), '+': ('1', 'unbounded'), '*': ('0', 'unbounded'), + '-1': ('0', 'unbounded'), } def __init__(self, sdf_root_dir: str): @@ -38,16 +39,15 @@ def _indent_lines(self, lines: List[str], indent) -> List[str]: def _get_attribute(self, element: ElementTree.Element, attrib: str) -> Optional[str]: return element.attrib[attrib] if attrib in element.attrib else None - def _is_std_type(self, element: ElementTree.Element) -> bool: - return self._get_attribute(element, 'type') in self.SDF_TYPES_TO_XSD_STD_TYPES.keys() + def _is_std_type(self, sdf_type: str) -> bool: + return sdf_type in self.SDF_TYPES_TO_XSD_STD_TYPES.keys() - def _xsd_type_string(self, element: ElementTree.Element) -> Optional[str]: - if self._is_std_type(element): - sdf_type = self._get_attribute(element, 'type') - if sdf_type: - xsd_type = self.SDF_TYPES_TO_XSD_STD_TYPES[sdf_type] - return 'xsd:' + xsd_type - return None + def _xsd_type_string(self, sdf_type: str) -> Optional[str]: + if self._is_std_type(sdf_type): + xsd_type = self.SDF_TYPES_TO_XSD_STD_TYPES[sdf_type] + return 'xsd:' + xsd_type + else: + return None def _print_documentation(self, element: ElementTree.Element) -> List[str]: lines = [] @@ -85,31 +85,37 @@ def _print_include_ref(self, element: ElementTree.Element) -> List[str]: print(f'Invalid sdf included {filename}') return lines - def _print_element(self, element: ElementTree.Element) -> List[str]: + def _print_plugin_element(self, element: ElementTree.Element) -> List[str]: lines = [] - # Short circuit for plugin.sdf copy_data element if 'copy_data' in element.attrib: lines.append('') lines.append(" ") lines.append('') - return lines + return lines + + def _print_element(self, element: ElementTree.Element) -> List[str]: + lines = [] elem_name = self._get_attribute(element, 'name') - elem_type = self._xsd_type_string(element) + elem_type = self._get_attribute(element, 'type') elem_reqd = self._get_attribute(element, 'required') - minOccurs, maxOccurs = self.SDF_REQUIRED_TO_MIN_MAX_OCCURS[elem_reqd] - lines.append(f"") + if elem_type and self._is_std_type(elem_type): + elem_type = self._xsd_type_string(elem_type) - if elem_type: + if elem_reqd: + minOccurs, maxOccurs = self.SDF_REQUIRED_TO_MIN_MAX_OCCURS[elem_reqd] + lines.append(f"") + + if elem_type is None: lines.append(f"") lines.extend(self._indent_lines(self._print_documentation(element), 2)) lines.append(" ") lines.append(" ") for e in element.findall('element'): - lines.extend(self._indent_lines(self._print_element(e), 2)) + lines.extend(self._indent_lines(self._print_element(e), 6)) lines.append(" ") @@ -129,10 +135,13 @@ def _print_attribute(self, element: ElementTree.Element) -> List[str]: lines = [] elem_name = self._get_attribute(element, 'name') - elem_type = self._xsd_type_string(element) + elem_type = self._get_attribute(element, 'type') elem_reqd = self._get_attribute(element, 'required') elem_default = self._get_attribute(element, 'default') + if elem_type and self._is_std_type(elem_type): + elem_type = self._xsd_type_string(elem_type) + use = "" default = "" @@ -140,8 +149,8 @@ def _print_attribute(self, element: ElementTree.Element) -> List[str]: use = "use='required'" elif elem_reqd == "0": use = "use='optional'" - if elem_default: - default = f"default='{elem_default}';'" + if elem_default is not None: + default = f"default='{elem_default}'" lines.append(f"") lines.extend(self._indent_lines(self._print_documentation(element), 2)) @@ -150,7 +159,10 @@ def _print_attribute(self, element: ElementTree.Element) -> List[str]: def _print_xsd(self, element: ElementTree.Element) -> List[str]: lines = [] + elem_name = self._get_attribute(element, 'name') + elem_type = self._get_attribute(element, 'type') + elements = element.findall('element') attributes = element.findall('attribute') includes = element.findall('include') @@ -170,7 +182,10 @@ def _print_xsd(self, element: ElementTree.Element) -> List[str]: lines.append(" ") for child_element in elements: - lines.extend(self._indent_lines(self._print_element(child_element), 4)) + if 'copy_data' in child_element.attrib: + lines.extend(self._indent_lines(self._print_plugin_element(child_element), 4)) + else: + lines.extend(self._indent_lines(self._print_element(child_element), 6)) for include_element in includes: lines.extend(self._indent_lines(self._print_include_ref(include_element), 6)) @@ -184,10 +199,11 @@ def _print_xsd(self, element: ElementTree.Element) -> List[str]: lines.append(" ") lines.append(f"") else: - elem_type = self._xsd_type_string(element) - - if elem_type is None: + if elem_type and self._is_std_type(elem_type): + elem_type = self._xsd_type_string(elem_type) + else: elem_type = "" + lines.append(f"") return lines