Skip to content

Commit 73c599d

Browse files
committed
Allow inserting feature flag macros on info fields
1 parent 30d3f48 commit 73c599d

File tree

4 files changed

+36
-11
lines changed

4 files changed

+36
-11
lines changed

epicsdbbuilder/recordbase.py

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ def add_comment(self, comment):
142142
def add_metadata(self, metadata):
143143
self.__comments.append('#% ' + metadata)
144144

145-
def add_info(self, name, info):
146-
self.__infos.append((name, info))
145+
def add_info(self, name, info, feature_flag=""):
146+
self.__infos.append((name, info, feature_flag))
147147

148148
def __dbd_order(self, fields):
149149
field_set = set(fields)
@@ -176,9 +176,13 @@ def Print(self, output, alphabetical=True):
176176
sort = sorted if alphabetical else list
177177
for alias in sort(self.__aliases.keys()):
178178
print(' alias("%s")' % alias, file = output)
179-
for name, info in self.__infos:
180-
value = self.__FormatFieldForDb(name, info)
181-
print(' info(%s, %s)' % (name, value), file = output)
179+
for name, info, feature_flag in self.__infos:
180+
# Restrict to one line if there is a feature flag so that it can be escaped
181+
feature_flag_macro = "$(%s=#)" % feature_flag if feature_flag else ""
182+
value = self.__FormatFieldForDb(name, info, line_prefix=feature_flag_macro)
183+
print(
184+
'%s info(%s, %s)' % (feature_flag_macro, name, value), file = output
185+
)
182186
print('}', file = output)
183187

184188

@@ -227,13 +231,15 @@ def __ValidateField(self, fieldname, value):
227231
self._validate.ValidFieldValue(fieldname, str(value))
228232

229233
# Field formatting
230-
def __FormatFieldForDb(self, fieldname, value):
234+
def __FormatFieldForDb(self, fieldname, value, line_prefix=""):
231235
if hasattr(value, 'FormatDb'):
232236
return value.FormatDb(self, fieldname)
233237
elif isinstance(value, dict):
234238
# JSON values in EPICS database as per
235239
# https://epics.anl.gov/base/R7-0/6-docs/links.html
236-
return '\n '.join(json.dumps(value, indent=4).splitlines())
240+
return '\n{} '.format(line_prefix).join(
241+
json.dumps(value, indent=4).splitlines()
242+
)
237243
else:
238244
return quote_string(str(value))
239245

test/expected_output.db

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file was automatically generated on Thu 25 Nov 2021 10:35:33 GMT.
2-
#
2+
#
33
# *** Please do not edit this file: edit the source file instead. ***
4-
#
4+
#
55
#% macro, DEVICE, Device name
66
#% macro, P, A parameter
77
#% macro, Q, A number
@@ -100,6 +100,15 @@ record(waveform, "$(DEVICE):FIELD:WITH_CONST_ARRAY")
100100
}
101101
}
102102
})
103+
$(V4=#) info(Q:group, {
104+
$(V4=#) "MYTABLE2": {
105+
$(V4=#) "+id": "epics:nt/NTTable:1.0",
106+
$(V4=#) "labels": {
107+
$(V4=#) "+type": "plain",
108+
$(V4=#) "+channel": "VAL"
109+
$(V4=#) }
110+
$(V4=#) }
111+
$(V4=#) })
103112
}
104113

105114
record(ai, "$(DEVICE):FIELD:WITH_JSON_LINK")

test/expected_output_alphabetical.db

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# This file was automatically generated on Mon 08 Nov 2021 09:23:43 GMT.
2-
#
2+
#
33
# *** Please do not edit this file: edit the source file instead. ***
4-
#
4+
#
55
#% macro, DEVICE, Device name
66
#% macro, P, A parameter
77
#% macro, Q, A number
@@ -23,6 +23,15 @@ record(waveform, "$(DEVICE):FIELD:WITH_CONST_ARRAY")
2323
}
2424
}
2525
})
26+
$(V4=#) info(Q:group, {
27+
$(V4=#) "MYTABLE2": {
28+
$(V4=#) "+id": "epics:nt/NTTable:1.0",
29+
$(V4=#) "labels": {
30+
$(V4=#) "+type": "plain",
31+
$(V4=#) "+channel": "VAL"
32+
$(V4=#) }
33+
$(V4=#) }
34+
$(V4=#) })
2635
}
2736

2837
record(ai, "$(DEVICE):FIELD:WITH_JSON_LINK")

test/test_a_file.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ def test_output(tmp_path):
7474
("+channel", "VAL")
7575
]))])
7676
w.add_info("Q:group", {"MYTABLE": td})
77+
w.add_info("Q:group", {"MYTABLE2": td}, "V4")
7778
# And json links with readbacks
7879
a = records.ai(
7980
'FIELD:WITH_JSON_LINK',

0 commit comments

Comments
 (0)