Skip to content

Commit a7dab5f

Browse files
authored
lestarch: updating fprime-gds to check dictionary framework_version (#593)
1 parent 8327000 commit a7dab5f

File tree

3 files changed

+42
-4
lines changed

3 files changed

+42
-4
lines changed

src/fprime_gds/common/loaders/xml_loader.py

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from fprime.common.models.serialize.serializable_type import SerializableType
4040
from fprime.common.models.serialize.string_type import StringType
4141
from fprime_gds.common.data_types import exceptions
42+
from fprime_gds.version import MINIMUM_SUPPORTED_FRAMEWORK_VERSION, MAXIMUM_SUPPORTED_FRAMEWORK_VERSION
4243

4344
# Custom Python Modules
4445
from . import dict_loader
@@ -114,11 +115,21 @@ def get_xml_tree(path):
114115
xml_parser = etree.XMLParser(remove_comments=True)
115116

116117
with open(path) as fd:
117-
118118
# Parse xml and get element tree object we can retrieve data from
119119
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
122133

123134
@staticmethod
124135
def get_xml_section(section_name, xml_root):
@@ -389,3 +400,15 @@ def parse_type(self, type_name, xml_item, xml_tree):
389400
raise exceptions.GseControllerParsingException(
390401
"Could not find type %s" % type_name
391402
)
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)))

src/fprime_gds/flask/app.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
####
88
import logging
99
import os
10+
import sys
1011

1112
import flask
1213
import flask_restful
@@ -131,7 +132,12 @@ def construct_app():
131132
return app, api
132133

133134

134-
app, _ = construct_app()
135+
try:
136+
app, _ = construct_app()
137+
except Exception as exc:
138+
print("[ERROR] {}".format(exc), file=sys.stderr)
139+
sys.exit(1)
140+
135141

136142

137143
@app.route("/js/<path:path>")

src/fprime_gds/version.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
''' Versioning information for the GDS
2+
3+
This file contains versioning and compatibility definitions for the GDS tool set.
4+
'''
5+
6+
# Currently the GDS is backwards compatible with all dictionaries. This MUST be bumped with each framework release to
7+
# ensure compatibility
8+
MINIMUM_SUPPORTED_FRAMEWORK_VERSION = (0,0,0)
9+
MAXIMUM_SUPPORTED_FRAMEWORK_VERSION = (1,5,4)

0 commit comments

Comments
 (0)