Skip to content

Commit

Permalink
enable regex database args
Browse files Browse the repository at this point in the history
  • Loading branch information
gilesknap committed Jun 21, 2024
1 parent 0c8a825 commit d88b9e8
Show file tree
Hide file tree
Showing 10 changed files with 1,377 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/ibek/render_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
support module yaml files.
"""

import re
from dataclasses import dataclass
from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple

Expand Down Expand Up @@ -74,15 +75,30 @@ def add_database(self, database: Database, entity: Entity) -> None:
if str_to_bool(UTILS.render(entity, database.enabled)):
database.file = database.file.strip("\n")

parameters = entity.__dict__.keys()
# take each database parameter and expand it into the set of
# entity parameters that it matches using regex
expanded_database_entries: dict[str, str] = {}
for arg, value in database.args.items():
if "*" in arg or "?" in arg:
# this is a regex - match the parameters to the regex
for parameter in parameters:
if re.match(arg, parameter):
# TODO - should we perform regex subst on the value as well?
expanded_database_entries[parameter] = value
else:
# simple db argument name
expanded_database_entries[arg] = value

for arg, value in expanded_database_entries.items():
if value is None:
if arg not in entity.__dict__ and arg not in UTILS.variables:
raise ValueError(
f"database arg '{arg}' in database template "
f"'{database.file}' not found in context"
)

self.add_row(database.file, database.args, entity)
self.add_row(database.file, expanded_database_entries, entity)

def add_extra_databases(self, databases: List[Tuple[Database, Entity]]) -> None:
"""Add databases that are not part of EntityModels
Expand Down
13 changes: 13 additions & 0 deletions tests/generate_samples.sh
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,16 @@ ibek ioc generate-schema --no-ibek-defs support/fastVacuum.ibek.support.yaml --o
echo making fastVacuum ioc
EPICS_ROOT=`pwd`/epics ibek runtime generate iocs/fastVacuum.ibek.ioc.yaml support/fastVacuum.ibek.support.yaml
mv `pwd`/epics/{runtime,opi}/* `pwd`/outputs/fastVacuum



############################################################################
# vacValveDebounce (dlsPLC) example
############################################################################

echo making an ioc schema using dlsPLC support yaml
ibek ioc generate-schema --no-ibek-defs support/dlsPLC.ibek.support.yaml support/asyn.ibek.support.yaml --output schemas/dlsPLC.ibek.ioc.schema.json

echo making fastVacuum ioc
EPICS_ROOT=`pwd`/epics ibek runtime generate iocs/dlsPLC.ibek.ioc.yaml support/dlsPLC.ibek.support.yaml support/asyn.ibek.support.yaml
mv `pwd`/epics/{runtime,opi}/* `pwd`/outputs/dlsPLC
18 changes: 18 additions & 0 deletions tests/samples/iocs/dlsPLC.ibek.ioc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# yaml-language-server: $schema=../schemas/dlsPLC.ibek.ioc.schema.json

ioc_name: "{{ _global.get_env('IOC_NAME') }}"

description: auto-generated by https://github.com/epics-containers/builder2ibek

entities:
- type: asyn.AsynIP
name: VLVCC_01_EIP
port: DUMMY

- type: dlsPLC.NX102_vacValveDebounce
ILKNUM: 1
device: SR03A-VA-VALVE-01
name: V1
port: VLVCC_01_EIP
tag: V
tagidx: 1
28 changes: 28 additions & 0 deletions tests/samples/outputs/dlsPLC/index.bob
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<display version="2.0.0">
<name></name>
<x>0</x>
<y use_class="true">0</y>
<width>10</width>
<height>35</height>
<grid_step_x>4</grid_step_x>
<grid_step_y>4</grid_step_y>
<widget type="label" version="2.0.0">
<name>Title</name>
<class>TITLE</class>
<text>Title</text>
<x use_class="true">0</x>
<y use_class="true">0</y>
<width>10</width>
<height>25</height>
<font use_class="true">
<font name="Header 1" family="Liberation Sans" style="BOLD" size="22.0">
</font>
</font>
<foreground_color use_class="true">
<color name="Text" red="0" green="0" blue="0">
</color>
</foreground_color>
<transparent use_class="true">true</transparent>
<horizontal_alignment>1</horizontal_alignment>
</widget>
</display>
9 changes: 9 additions & 0 deletions tests/samples/outputs/dlsPLC/ioc.subst
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#############################################################################
# DB substitution file generated by http://github.com/epics-containers/ibek #
#############################################################################

file "$(DLSPLC)/db/NX102_vacValveDebounce.template" {
pattern
{ "type", "entity_enabled", "mode1", "mode2", "ilksta_sv0", "ilksta_sv1", "ilksta_sv2", "ilksta_sv3", "ilksta_sv4", "ilksta_sv5", "ilksta_label0", "ilksta_label1", "ilksta_label2", "ilksta_label3", "ilksta_label4", "ilksta_label5", "sta_sv0", "sta_sv1", "sta_sv2", "sta_sv3", "sta_sv4", "sta_sv5", "sta_sv6", "sta_label0", "sta_label1", "sta_label2", "sta_label3", "sta_label4", "sta_label5", "sta_label6", "con_label0", "con_label1", "con_label2", "con_label3", "con_label4", "con_label5", "con_label6", "whylocked", "allowpv", "tagidx", "tag", "ILKNUM", "device", "port", "con_label7", "sta_label7", "sta_sv7", "ilksta_label6", "ilksta_label7", "ilksta_sv6", "ilksta_sv7", "DIRILK1", "DIRILK2", "name", "desc" }
{ "dlsPLC.NX102_vacValveDebounce", "True", "Operational", "Service", "MAJOR", "NO_ALARM", "NO_ALARM", "NO_ALARM", "NO_ALARM", "NO_ALARM", "Failed", "Run Ilks Ok", "OK", "Disarmed", "", "", "MAJOR", "NO_ALARM", "NO_ALARM", "NO_ALARM", "NO_ALARM", "NO_ALARM", "NO_ALARM", "Fault", "Open", "Opening", "Closed", "Closing", "", "", "Open", "Close", "Reset", "", "", "", "", "Open command not allowed", "", "1", "V", "1", "SR03A-VA-VALVE-01", "VLVCC_01_EIP", "", "", "NO_ALARM", "", "", "NO_ALARM", "NO_ALARM", "", "ILK2", "V1", "$(device)" }
}
19 changes: 19 additions & 0 deletions tests/samples/outputs/dlsPLC/st.cmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# EPICS IOC Startup Script generated by https://github.com/epics-containers/ibek

cd "/epics/ioc"

epicsEnvSet NAME_AS_ENV_VAR my name is VLVCC_01_EIP

dbLoadDatabase dbd/ioc.dbd
ioc_registerRecordDeviceDriver pdbbase

# Setting up Asyn Port VLVCC_01_EIP on DUMMY:
# AsynIPConfigure({{name}}, {{port}}, {{stop}}, {{parity}}, {{bits}})
AsynIPConfigure(VLVCC_01_EIP, DUMMY, 1, none, 8)
asynSetOption(9600, 0, N, Y)
asynOctetSetInputEos("\n")
asynOctetSetOutputEos("\n")

dbLoadRecords /epics/runtime/ioc.db
iocInit

Loading

0 comments on commit d88b9e8

Please sign in to comment.