Skip to content

Commit

Permalink
Merge pull request #145 from klauer/fix_flnk_graph
Browse files Browse the repository at this point in the history
FIX: forward link edges + allow for stdin usage in `whatrecord [parse|graph]`
  • Loading branch information
klauer authored Sep 22, 2022
2 parents 7124496 + d843fd5 commit 1e71b0d
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 15 deletions.
23 changes: 19 additions & 4 deletions whatrecord/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ def add_database(self, database: Union[Dict[str, RecordInstance], Database]):
"""
).rstrip()

if li.field1.dtype == "DBF_INLINK":
if li.field1.dtype == "DBF_INLINK" or li.field2.dtype == "DBF_OUTLINK":
src, dest = dest, src
li.field1, li.field2 = li.field2, li.field1

Expand All @@ -753,9 +753,24 @@ def add_database(self, database: Union[Dict[str, RecordInstance], Database]):
break

if (src, dest) not in set(self.edge_pairs):
if "DBF_FWDLINK" in (li.field1.dtype, li.field2.dtype):
edge_kw["taillabel"] = "FLNK"
self.add_edge(src.label, dest.label, color="black", **edge_kw)
if li.field1.dtype == "DBF_FWDLINK":
# edge_kw["taillabel"] = "FLNK"
self.add_edge(
src.label,
dest.label,
color="black",
source_port=li.field1.name,
**edge_kw
)
elif li.field2.dtype == "DBF_FWDLINK":
# edge_kw["taillabel"] = "FLNK"
self.add_edge(
dest.label,
src.label,
color="black",
source_port=li.field2.name,
**edge_kw
)
else:
# edge_kw["taillabel"] = f"{li.field1.name}"
# edge_kw["headlabel"] = f"{li.field2.name}"
Expand Down
41 changes: 30 additions & 11 deletions whatrecord/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import asyncio
import logging
import pathlib
import sys
from typing import Dict, Optional, Union

from .access_security import AccessSecurityConfig
Expand Down Expand Up @@ -74,7 +75,24 @@ def parse(
"""
standin_directories = standin_directories or {}

filename = pathlib.Path(filename)
if str(filename) == "-":
if format is None:
options = [fmt.name for fmt in list(FileFormat)]
raise ValueError(
f"Format must be specified when piping data from standard "
f"input. Choose one of: {options}"
)
if format == FileFormat.iocsh:
raise ValueError(
"IOC shell script parsing not supported through standard input"
)

contents = sys.stdin.read()
filename = pathlib.Path(sys.stdin.name)
else:
with open(filename, "rt") as fp:
contents = fp.read()
filename = pathlib.Path(filename)

# The shared macro context - used in different ways below:
macro_context = MacroContext(macro_string=macros or "")
Expand All @@ -84,17 +102,21 @@ def parse(

if format in (FileFormat.database, FileFormat.database_definition):
if format == FileFormat.database_definition or not dbd:
return Database.from_file(
filename, macro_context=macro_context, version=3 if v3 else 4
return Database.from_string(
contents,
filename=filename,
macro_context=macro_context,
version=3 if v3 else 4
)
return Database.from_file(
filename,
return Database.from_string(
contents,
filename=filename,
dbd=Database.from_file(dbd, version=3 if v3 else 4),
macro_context=macro_context
)

if format == FileFormat.iocsh:
md = IocMetadata.from_file(
md = IocMetadata.from_filename(
filename,
standin_directories=standin_directories,
macros=dict(macro_context),
Expand All @@ -108,7 +130,7 @@ def parse(
return LoadedIoc.from_metadata(md)

if format == FileFormat.substitution:
template = TemplateSubstitution.from_file(filename)
template = TemplateSubstitution.from_string(contents, filename=filename)
if not expand:
return template

Expand All @@ -124,10 +146,7 @@ def parse(
)

if format == FileFormat.state_notation:
return SequencerProgram.from_file(filename)

with open(filename, "rt") as fp:
contents = fp.read()
return SequencerProgram.from_string(contents, filename=filename)

if macros:
contents = macro_context.expand_file(contents)
Expand Down

0 comments on commit 1e71b0d

Please sign in to comment.