-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsyfco.py
86 lines (65 loc) · 2.25 KB
/
syfco.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
import subprocess
# Note: not all functions of syfco are supported
syfco_path = "syfco"
def _run_command(arguments, input):
out = subprocess.run(
syfco_path + " " + arguments,
input=input,
shell=True,
capture_output=True,
text=True,
)
if out.stderr != "":
raise Exception(out.stderr)
return out.stdout
def _take_optional_args(
overwrite_params: dict = {},
transformations: list[str] = [],
mode="pretty",
quote="none",
):
return (
" ".join(
[
"-op " + key + "=" + str(value)
for (key, value) in overwrite_params.items()
]
+ ["-" + tf for tf in transformations]
)
+ " -m "
+ mode
+ " -q "
+ quote
)
def convert(input: str, format: str = "full", **kwargs):
"""
Takes a TLSF specification as input and converts it to the output format specificied
Optional Parameters:
- overwrite_params: dict to overwrite parameters in the TLSF input
- transformations: array that lists all of the transformations to apply, as described by syfco. Example could be ["s1"]
- mode: "pretty" [default] minimal parenthesis; "fully" fully parenthesized
- quote: "none" [default] do not quote identifiers; "double" quote identifiers using "
"""
args = f"-f {format} {_take_optional_args(**kwargs)} -in"
return _run_command(args, input).strip()
def inputs(input: str, **kwargs):
args = f"-f ltl {_take_optional_args(**kwargs)} -in -ins"
return [s.strip() for s in _run_command(args, input).split(",")]
def outputs(input: str, **kwargs) -> list[str]:
args = f"-f ltl {_take_optional_args(**kwargs)} -in -outs"
return [s.strip() for s in _run_command(args, input).split(",")]
def parameters(input: str):
args = f"-p -in "
return [s.strip() for s in _run_command(args, input).split(",")]
def title(input: str) -> str:
args = f"-t -in"
return _run_command(args, input)[:-1]
def description(input: str) -> str:
args = f"-d -in"
return _run_command(args, input)[:-1]
def check(input: str) -> bool:
args = f"-c -in"
try:
return "valid" in _run_command(args, input)
except Exception:
return False