Skip to content

Commit

Permalink
FIX/CLN: streamdevice annotation serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
klauer committed Sep 28, 2023
1 parent bf316ec commit 629e80d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 29 deletions.
2 changes: 1 addition & 1 deletion whatrecord/shell.py
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ def handle_dbLoadRecords(self, filename: str, macros: str = ""):
if annotation:
key = StringWithContext(
self.streamdevice.metadata_key,
context=record.context,
context=(),
)
record.metadata[key] = annotation

Expand Down
57 changes: 29 additions & 28 deletions whatrecord/streamdevice.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from epicsmacrolib import split_iocsh_line

from . import transformer
from .common import (AnyPath, FullLoadContext, ShellStateHandler,
from .common import (AnyPath, FullLoadContext, LoadContext, ShellStateHandler,
StringWithContext)
from .db import PVAFieldReference, RecordInstance
from .transformer import context_from_token
Expand Down Expand Up @@ -165,10 +165,10 @@ def standalone_variable_ref(self, ref, *_):
arguments=[],
)

def config_set(self, command):
def config_set(self, command: lark.Tree):
return ConfigurationSetting(
name=command.data,
value=" ".join(command.children),
name=str(command.data),
value=" ".join(str(child) for child in command.children),
)

value_part = transformer.pass_through
Expand Down Expand Up @@ -337,34 +337,35 @@ def annotate_record(self, record: RecordInstance) -> Optional[Dict[str, Any]]:
}

info_field = info_field.value.strip()
results = {}
annotation: Dict[str, Any] = {
"context": [],
}
try:
proto_file, proto_name, *proto_args = split_iocsh_line(info_field).argv
proto_file = proto_file.lstrip("@ ")
except Exception:
results["error"] = (
annotation["error"] = (
f"Invalid StreamDevice input/output field: {info_field!r}"
)
proto_file = None
proto_name = None
proto_args = []
return annotation

try:
protocol = self.load_streamdevice_protocol(proto_file)
except Exception as ex:
annotation["error"] = f"{ex.__class__.__name__}: {ex}"
protocol = None
return annotation

if proto_name in protocol.protocols:
specific_protocol = protocol.protocols[proto_name]
annotation["context"] = specific_protocol.context
annotation["protocol"] = specific_protocol
else:
try:
protocol = self.load_streamdevice_protocol(proto_file)
except Exception as ex:
results["error"] = f"{ex.__class__.__name__}: {ex}"
else:
if proto_name in protocol.protocols:
results["protocol"] = protocol.protocols[proto_name]
else:
results["error"] = (
f"Unknown protocol {proto_name!r} in {proto_file}; "
f"options are: {list(protocol.protocols)}"
)

return {
"protocol_file": proto_file,
"protocol_name": proto_name,
"protocol_args": proto_args,
**results,
}
annotation["context"] = [LoadContext(proto_file, 0)]
annotation["error"] = (
f"Unknown protocol {proto_name!r} in {proto_file}; "
f"options are: {list(protocol.protocols)}"
)
annotation["protocol_name"] = proto_name
annotation["protocol_args"] = proto_args
return annotation

0 comments on commit 629e80d

Please sign in to comment.