Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion src/fprime_gds/common/data_types/event_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from fprime_gds.common.data_types import sys_data
from fprime_gds.common.utils.string_util import format_string_template

import os

class EventData(sys_data.SysData):
"""
Expand Down Expand Up @@ -40,10 +41,20 @@ def __init__(self, event_args, event_time, event_temp):
self.args = event_args
self.time = event_time
self.template = event_temp

if event_args is None:
self.display_text = event_temp.description
elif event_temp.format_str == "":
return

if (
(event_temp.name.startswith('AF_ASSERT') or event_temp.name == "AF_UNEXPECTED_ASSERT") and
'FPRIME_HASHES_TXT_FILE' in os.environ
):
self._decode_hashed_files()

if event_temp.format_str == "":
args_template = self.template.get_args()

self.display_text = str(
[
{args_template[index][0]: arg.val}
Expand All @@ -55,6 +66,28 @@ def __init__(self, event_args, event_time, event_temp):
event_temp.format_str, tuple([arg.val for arg in event_args])
)

def _decode_hashed_files(self):
"Searches event args for hashed files and replaces each with its corresponding file name"

args_template = self.template.get_args()
for index, arg in enumerate(self.args):

if not args_template[index]:
continue
if args_template[index][0] != 'file':
continue
try:
hash_value = int(arg.val, 16)
except ValueError:
continue

hash_file = os.environ['FPRIME_HASHES_TXT_FILE']
with open(hash_file) as file_handle:
for line in file_handle:
if hash_value == int(line.split(" ")[-1], 0):
arg.val = line.split(':')[0].strip()
break

def get_args(self):
return self.args

Expand Down
34 changes: 34 additions & 0 deletions src/fprime_gds/executables/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -1045,6 +1045,39 @@ def handle_arguments(self, args, **kwargs):
return args


class HashFileParser(DictionaryParser):
"""Parser for detecting and loading the hashes.txt file for hash decoding"""

DESCRIPTION = "Hash file options"

def get_arguments(self)-> Dict[Tuple[str, ...], Dict[str, Any]]:
return {
("--hash-file",): {
"dest": "hash_file",
"action": "store",
"required": False,
"type": str,
"help": "Path to hashes.txt file map (found under build-artifacts dir by default)",
}
}

def handle_arguments(self, args, **kwargs):
if args.hash_file:
args.hash_file = Path(args.hash_file)
if not args.hash_file.exists():
msg = f"[ERROR] hash file location {args.hash_file} does not exist"
print(msg, file=sys.stderr)
sys.exit(-1)
return args

if args.deployment is None:
super().handle_arguments(args, **kwargs)
if args.deployment:
hash_file = (Path(args.deployment) / ".."/ ".." / "hashes.txt").resolve()
args.hash_file = hash_file if hash_file.exists() else None
return args


class FileHandlingParser(ParserBase):
"""Parser for deployments"""

Expand Down Expand Up @@ -1106,6 +1139,7 @@ class StandardPipelineParser(CompositeParser):

CONSTITUENTS = [
DictionaryParser,
HashFileParser,
FileHandlingParser,
MiddleWareParser,
LogDeployParser,
Expand Down
2 changes: 2 additions & 0 deletions src/fprime_gds/executables/run_deployment.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ def launch_html(parsed_args):
"SERVE_LOGS": "YES",
}
)
if parsed_args.hash_file:
flask_env.update({"FPRIME_HASHES_TXT_FILE": parsed_args.hash_file})
gse_args = BASE_MODULE_ARGUMENTS + [
"flask",
"run",
Expand Down
Loading