Skip to content

Commit b0fed5f

Browse files
authored
DP Write Fix & Refactor for Easier Usage as a Library (#265)
* Remove annotation field from record & container structs * Break data_product_writer self.process() into 2 functions for use as library * Add `fdp` to expect.txt * Remove printing of record.id for every record
1 parent 561c51d commit b0fed5f

File tree

2 files changed

+34
-12
lines changed

2 files changed

+34
-12
lines changed

.github/actions/spelling/expect.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ exts
140140
fastentrypoints
141141
fbuild
142142
fd
143+
fdp
143144
FEEDNAME
144145
feq
145146
FFCC

src/fprime_gds/executables/data_product_writer.py

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,11 @@ class RecordStruct(BaseModel):
264264
type: Union[AliasType, StructType, ArrayType, IntegerType, FloatType, BoolType, QualifiedType, StringType]
265265
array: bool
266266
id: int
267-
annotation: str
268267

269268
class ContainerStruct(BaseModel):
270269
name: str
271270
id: int
272271
defaultPriority: int
273-
annotation: str
274272

275273
# -------------------------------------------------------------------------------------
276274
# These Pydantic classes define the FPRIME_DICTIONARY_FILE
@@ -771,7 +769,6 @@ def get_record_data(self, headerJSON: DPHeader, dictJSON: FprimeDict) -> Dict[st
771769
rootDict['dataId'] = self.read_field(headerJSON.dataId.underlyingType)
772770
for record in dictJSON.records:
773771
if record.id == rootDict['dataId']:
774-
print(f'Processing Record ID {record.id}')
775772
if record.array:
776773
dataSize = self.read_field(headerJSON.dataSize.type)
777774
rootDict['size'] = dataSize
@@ -844,17 +841,17 @@ def check_record_data(self, dictJSON: FprimeDict):
844841
idSet.add(record.id)
845842

846843

847-
848-
# -------------------------------------------------------------------------------------------------------------------------
849-
# Function process
844+
# ----------------------------------------------------------------------------------------------
845+
# Function: get_records
850846
#
851-
# Description:
852-
# Main processing
853-
# -------------------------------------------------------------------------------------------------------------------------
854-
def process(self):
855-
847+
# Description:
848+
# Reads all the records from the fdp file
849+
#
850+
# Returns:
851+
# List[Dict[str, obj]]: A list of dictionaries populated with the header followed by all records.
852+
# ----------------------------------------------------------------------------------------------
853+
def get_records(self):
856854
try:
857-
858855
# Read the F prime JSON dictionary
859856
print(f"Parsing {self.jsonDict}...")
860857
try:
@@ -908,7 +905,20 @@ def process(self):
908905
msg = f'ValueError in JSON file {error["loc"]}: {error["msg"]}'
909906
self.handleException(msg)
910907

908+
return recordList
911909

910+
# ----------------------------------------------------------------------------------------------
911+
# Function: write_records
912+
#
913+
# Description:
914+
# Writes all records to a json file
915+
#
916+
# Parameters:
917+
# recordList (List[Dict[str, obj]]): A list of dictionaries populated with the header followed by all records.
918+
#
919+
# Returns:
920+
# ----------------------------------------------------------------------------------------------
921+
def write_records(self, recordList):
912922
# Output the generated json to a file
913923
baseName = os.path.basename(self.binaryFileName)
914924
outputJsonFile = os.path.splitext(baseName)[0] + '.json'
@@ -919,6 +929,17 @@ def process(self):
919929

920930
print(f'Output data generated in {outputJsonFile}')
921931

932+
# -------------------------------------------------------------------------------------------------------------------------
933+
# Function process
934+
#
935+
# Description:
936+
# Main processing: parses records from the fdp file, then writes all records to a json file
937+
# -------------------------------------------------------------------------------------------------------------------------
938+
def process(self):
939+
recordList = self.get_records()
940+
941+
self.write_records(recordList)
942+
922943

923944
# ------------------------------------------------------------------------------------------
924945
# main program

0 commit comments

Comments
 (0)