Skip to content

Commit 7c37a93

Browse files
committed
Fix small differences
Signed-off-by: Michael Carroll <[email protected]>
1 parent 49e7526 commit 7c37a93

File tree

7 files changed

+46
-30
lines changed

7 files changed

+46
-30
lines changed

sdf/1.10/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ foreach(FIL ${sdfs})
7373

7474
add_custom_command(
7575
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.xsd"
76-
COMMAND ${RUBY} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py
76+
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py
7777
ARGS --sdf-dir ${CMAKE_CURRENT_SOURCE_DIR} --input-file ${ABS_FIL} --output-dir ${CMAKE_CURRENT_BINARY_DIR}
7878
DEPENDS ${ABS_FIL}
7979
COMMENT "Running xml schema compiler on ${FIL}"

sdf/1.5/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ foreach(FIL ${sdfs})
6767

6868
add_custom_command(
6969
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.xsd"
70-
COMMAND ${RUBY} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py
70+
COMMAND ${Pyhton3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py
7171
ARGS --sdf-dir ${CMAKE_CURRENT_SOURCE_DIR} --input-file ${ABS_FIL} --output-dir ${CMAKE_CURRENT_BINARY_DIR}
7272
DEPENDS ${ABS_FIL}
7373
COMMENT "Running xml schema compiler on ${FIL}"

sdf/1.6/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ foreach(FIL ${sdfs})
7171

7272
add_custom_command(
7373
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.xsd"
74-
COMMAND ${RUBY} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py
74+
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py
7575
ARGS --sdf-dir ${CMAKE_CURRENT_SOURCE_DIR} --input-file ${ABS_FIL} --output-dir ${CMAKE_CURRENT_BINARY_DIR}
7676
DEPENDS ${ABS_FIL}
7777
COMMENT "Running xml schema compiler on ${FIL}"

sdf/1.7/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ foreach(FIL ${sdfs})
7272

7373
add_custom_command(
7474
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.xsd"
75-
COMMAND ${RUBY} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py
75+
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py
7676
ARGS --sdf-dir ${CMAKE_CURRENT_SOURCE_DIR} --input-file ${ABS_FIL} --output-dir ${CMAKE_CURRENT_BINARY_DIR}
7777
DEPENDS ${ABS_FIL}
7878
COMMENT "Running xml schema compiler on ${FIL}"

sdf/1.8/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ foreach(FIL ${sdfs})
7474

7575
add_custom_command(
7676
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.xsd"
77-
COMMAND ${RUBY} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py
77+
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py
7878
ARGS --sdf-dir ${CMAKE_CURRENT_SOURCE_DIR} --input-file ${ABS_FIL} --output-dir ${CMAKE_CURRENT_BINARY_DIR}
7979
DEPENDS ${ABS_FIL}
8080
COMMENT "Running xml schema compiler on ${FIL}"

sdf/1.9/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ foreach(FIL ${sdfs})
7474

7575
add_custom_command(
7676
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.xsd"
77-
COMMAND ${RUBY} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py
77+
COMMAND ${Python3_EXECUTABLE} ${CMAKE_SOURCE_DIR}/tools/xmlschema.py
7878
ARGS --sdf-dir ${CMAKE_CURRENT_SOURCE_DIR} --input-file ${ABS_FIL} --output-dir ${CMAKE_CURRENT_BINARY_DIR}
7979
DEPENDS ${ABS_FIL}
8080
COMMENT "Running xml schema compiler on ${FIL}"

tools/xmlschema.py

Lines changed: 40 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class XmlSchema:
2727
'1': ('1', '1'),
2828
'+': ('1', 'unbounded'),
2929
'*': ('0', 'unbounded'),
30+
'-1': ('0', 'unbounded'),
3031
}
3132

3233
def __init__(self, sdf_root_dir: str):
@@ -38,16 +39,15 @@ def _indent_lines(self, lines: List[str], indent) -> List[str]:
3839
def _get_attribute(self, element: ElementTree.Element, attrib: str) -> Optional[str]:
3940
return element.attrib[attrib] if attrib in element.attrib else None
4041

41-
def _is_std_type(self, element: ElementTree.Element) -> bool:
42-
return self._get_attribute(element, 'type') in self.SDF_TYPES_TO_XSD_STD_TYPES.keys()
42+
def _is_std_type(self, sdf_type: str) -> bool:
43+
return sdf_type in self.SDF_TYPES_TO_XSD_STD_TYPES.keys()
4344

44-
def _xsd_type_string(self, element: ElementTree.Element) -> Optional[str]:
45-
if self._is_std_type(element):
46-
sdf_type = self._get_attribute(element, 'type')
47-
if sdf_type:
48-
xsd_type = self.SDF_TYPES_TO_XSD_STD_TYPES[sdf_type]
49-
return 'xsd:' + xsd_type
50-
return None
45+
def _xsd_type_string(self, sdf_type: str) -> Optional[str]:
46+
if self._is_std_type(sdf_type):
47+
xsd_type = self.SDF_TYPES_TO_XSD_STD_TYPES[sdf_type]
48+
return 'xsd:' + xsd_type
49+
else:
50+
return None
5151

5252
def _print_documentation(self, element: ElementTree.Element) -> List[str]:
5353
lines = []
@@ -85,31 +85,37 @@ def _print_include_ref(self, element: ElementTree.Element) -> List[str]:
8585
print(f'Invalid sdf included {filename}')
8686
return lines
8787

88-
def _print_element(self, element: ElementTree.Element) -> List[str]:
88+
def _print_plugin_element(self, element: ElementTree.Element) -> List[str]:
8989
lines = []
90-
9190
# Short circuit for plugin.sdf copy_data element
9291
if 'copy_data' in element.attrib:
9392
lines.append('<xsd:sequence>')
9493
lines.append(" <xsd:any minOccurs='0' maxOccurs='unbounded' processContents='lax'/>")
9594
lines.append('</xsd:sequence>')
96-
return lines
95+
return lines
96+
97+
def _print_element(self, element: ElementTree.Element) -> List[str]:
98+
lines = []
9799

98100
elem_name = self._get_attribute(element, 'name')
99-
elem_type = self._xsd_type_string(element)
101+
elem_type = self._get_attribute(element, 'type')
100102
elem_reqd = self._get_attribute(element, 'required')
101103

102-
minOccurs, maxOccurs = self.SDF_REQUIRED_TO_MIN_MAX_OCCURS[elem_reqd]
103-
lines.append(f"<xsd:choice minOccurs='{minOccurs}' maxOccurs='{maxOccurs}'>")
104+
if elem_type and self._is_std_type(elem_type):
105+
elem_type = self._xsd_type_string(elem_type)
104106

105-
if elem_type:
107+
if elem_reqd:
108+
minOccurs, maxOccurs = self.SDF_REQUIRED_TO_MIN_MAX_OCCURS[elem_reqd]
109+
lines.append(f"<xsd:choice minOccurs='{minOccurs}' maxOccurs='{maxOccurs}'>")
110+
111+
if elem_type is None:
106112
lines.append(f"<xsd:element name='{elem_name}'>")
107113
lines.extend(self._indent_lines(self._print_documentation(element), 2))
108114
lines.append(" <xsd:complexType>")
109115
lines.append(" <xsd:choice maxOccurs='unbounded'>")
110116

111117
for e in element.findall('element'):
112-
lines.extend(self._indent_lines(self._print_element(e), 2))
118+
lines.extend(self._indent_lines(self._print_element(e), 6))
113119

114120
lines.append(" </xsd:choice>")
115121

@@ -129,19 +135,22 @@ def _print_attribute(self, element: ElementTree.Element) -> List[str]:
129135
lines = []
130136

131137
elem_name = self._get_attribute(element, 'name')
132-
elem_type = self._xsd_type_string(element)
138+
elem_type = self._get_attribute(element, 'type')
133139
elem_reqd = self._get_attribute(element, 'required')
134140
elem_default = self._get_attribute(element, 'default')
135141

142+
if elem_type and self._is_std_type(elem_type):
143+
elem_type = self._xsd_type_string(elem_type)
144+
136145
use = ""
137146
default = ""
138147

139148
if elem_reqd == "1":
140149
use = "use='required'"
141150
elif elem_reqd == "0":
142151
use = "use='optional'"
143-
if elem_default:
144-
default = f"default='{elem_default}';'"
152+
if elem_default is not None:
153+
default = f"default='{elem_default}'"
145154

146155
lines.append(f"<xsd:attribute name='{elem_name}' type='{elem_type}' {use} {default}>")
147156
lines.extend(self._indent_lines(self._print_documentation(element), 2))
@@ -150,7 +159,10 @@ def _print_attribute(self, element: ElementTree.Element) -> List[str]:
150159

151160
def _print_xsd(self, element: ElementTree.Element) -> List[str]:
152161
lines = []
162+
153163
elem_name = self._get_attribute(element, 'name')
164+
elem_type = self._get_attribute(element, 'type')
165+
154166
elements = element.findall('element')
155167
attributes = element.findall('attribute')
156168
includes = element.findall('include')
@@ -170,7 +182,10 @@ def _print_xsd(self, element: ElementTree.Element) -> List[str]:
170182
lines.append(" <xsd:choice maxOccurs='unbounded'>")
171183

172184
for child_element in elements:
173-
lines.extend(self._indent_lines(self._print_element(child_element), 4))
185+
if 'copy_data' in child_element.attrib:
186+
lines.extend(self._indent_lines(self._print_plugin_element(child_element), 4))
187+
else:
188+
lines.extend(self._indent_lines(self._print_element(child_element), 6))
174189

175190
for include_element in includes:
176191
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]:
184199
lines.append(" </xsd:complexType>")
185200
lines.append(f"</xsd:element>")
186201
else:
187-
elem_type = self._xsd_type_string(element)
188-
189-
if elem_type is None:
202+
if elem_type and self._is_std_type(elem_type):
203+
elem_type = self._xsd_type_string(elem_type)
204+
else:
190205
elem_type = ""
206+
191207
lines.append(f"<xsd:element name='{elem_name}'{elem_type} />")
192208
return lines
193209

0 commit comments

Comments
 (0)