|
39 | 39 | from fprime.common.models.serialize.serializable_type import SerializableType
|
40 | 40 | from fprime.common.models.serialize.string_type import StringType
|
41 | 41 | from fprime_gds.common.data_types import exceptions
|
| 42 | +from fprime_gds.version import MINIMUM_SUPPORTED_FRAMEWORK_VERSION, MAXIMUM_SUPPORTED_FRAMEWORK_VERSION |
42 | 43 |
|
43 | 44 | # Custom Python Modules
|
44 | 45 | from . import dict_loader
|
@@ -114,11 +115,21 @@ def get_xml_tree(path):
|
114 | 115 | xml_parser = etree.XMLParser(remove_comments=True)
|
115 | 116 |
|
116 | 117 | with open(path) as fd:
|
117 |
| - |
118 | 118 | # Parse xml and get element tree object we can retrieve data from
|
119 | 119 | element_tree = etree.parse(fd, parser=xml_parser)
|
120 |
| - |
121 |
| - return element_tree.getroot() |
| 120 | + root = element_tree.getroot() |
| 121 | + |
| 122 | + # Check version of the XML before continuing. Versions weren't published before 1.5.4. Only check major minor |
| 123 | + # and point versions to allow for development versions to be allowed. |
| 124 | + dict_version_string = root.attrib.get("framework_version", "1.5.4") |
| 125 | + try: |
| 126 | + dict_version = dict_version_string.split(".") |
| 127 | + dict_version = tuple([int(item) for item in dict_version[0:3]]) |
| 128 | + except (ValueError, IndexError): |
| 129 | + raise UnsupportedDictionaryVersionException(dict_version) |
| 130 | + if dict_version < MINIMUM_SUPPORTED_FRAMEWORK_VERSION or dict_version > MAXIMUM_SUPPORTED_FRAMEWORK_VERSION: |
| 131 | + raise UnsupportedDictionaryVersionException(dict_version) |
| 132 | + return root |
122 | 133 |
|
123 | 134 | @staticmethod
|
124 | 135 | def get_xml_section(section_name, xml_root):
|
@@ -389,3 +400,15 @@ def parse_type(self, type_name, xml_item, xml_tree):
|
389 | 400 | raise exceptions.GseControllerParsingException(
|
390 | 401 | "Could not find type %s" % type_name
|
391 | 402 | )
|
| 403 | + |
| 404 | + |
| 405 | +class UnsupportedDictionaryVersionException(Exception): |
| 406 | + """ Dictionary is of unsupported version """ |
| 407 | + def __init__(self, version): |
| 408 | + """ Create a dictionary of a specific version """ |
| 409 | + def pretty(version_tuple): |
| 410 | + """ Pretty print version """ |
| 411 | + return ".".join([str(item) for item in version_tuple]) |
| 412 | + super().__init__("Dictionary version {} is not in supported range: {}-{}. Please upgrade fprime-gds." |
| 413 | + .format(pretty(version), pretty(MINIMUM_SUPPORTED_FRAMEWORK_VERSION), |
| 414 | + pretty(MAXIMUM_SUPPORTED_FRAMEWORK_VERSION))) |
0 commit comments