convert types only before writing DB

This commit is contained in:
2024-11-15 18:08:08 +01:00
parent d128646650
commit 92fb7aa7ca
2 changed files with 9 additions and 10 deletions

View File

@ -1,6 +1,14 @@
import json
DTYPES = {
"float": "ai",
"int": "longin",
"bool": "bi",
"str": "stringin"
}
def load_data(fn):
try:
with open(fn) as f:
@ -16,6 +24,7 @@ def save_data(data, fn):
def mk_db(data, fn):
with open(fn, "w") as f:
for name, dtyp in data.items():
dtyp = DTYPES[dtyp]
entry = f'record({dtyp}, "$(SYSTEM):{name}") {{}}'
f.write(entry)
f.write("\n")

View File

@ -5,14 +5,6 @@ from log import log
from utils import toggle
DTYPES = {
"float": "ai",
"int": "longin",
"bool": "bi",
"str": "stringin"
}
FN_ENTRIES = "/ioc/data/SATES20-CPCL-DYNA/entries"
FN_DB_TMPL = "/ioc/data/SATES20-CPCL-DYNA/dynamic.template"
@ -30,7 +22,6 @@ def cb_add(value=None, **kwargs):
log.info(f"add: ignoring name={repr(name)}")
return
dtyp = pv_dtyp.get(as_string=True)
dtyp = DTYPES[dtyp]
log.info(f"add: name={repr(name)} type={repr(dtyp)} {kwargs}")
data = load_data(FN_ENTRIES)
data[name] = dtyp
@ -62,7 +53,6 @@ pv_remove = PV("SATES20-DYNA:REMOVE")
pv_remove.add_callback(cb_remove)
def mk_printable_data(data):
return "\n".join(f"{k} ({v})" for k, v in sorted(data.items()))