Skip to content
Snippets Groups Projects
Commit 188ca288 authored by Alexander Schlemmer's avatar Alexander Schlemmer
Browse files

FIX: variable substitution with referenced properties was not possible

parent 14df1174
No related branches found
No related tags found
2 merge requests!53Release 0.1,!21F use substitution templates
Pipeline #22881 failed
...@@ -91,9 +91,17 @@ def handle_value(value: Union[dict, str], values: GeneralStore): ...@@ -91,9 +91,17 @@ def handle_value(value: Union[dict, str], values: GeneralStore):
propvalue = value propvalue = value
return (propvalue, collection_mode) return (propvalue, collection_mode)
# Check if the replacement is a single variable containing a record:
match = re.match(r"^\$(\{)?(?P<varname>[0-9a-zA-Z_]+)(\})?$", propvalue)
if match is not None:
varname = match.group("varname")
if varname in values:
if isinstance(values[varname], db.Entity):
propvalue = values[varname]
return (propvalue, collection_mode)
propvalue_template = Template(propvalue) propvalue_template = Template(propvalue)
propvalue = propvalue_template.safe_substitute(**values.get_storage()) propvalue = propvalue_template.safe_substitute(**values.get_storage())
return (propvalue, collection_mode) return (propvalue, collection_mode)
......
...@@ -2,6 +2,9 @@ ...@@ -2,6 +2,9 @@
ExperimentalData: # name of the converter ExperimentalData: # name of the converter
type: Directory type: Directory
match: ExperimentalData match: ExperimentalData
records:
Project:
name: project
subtree: subtree:
File: # name of the converter File: # name of the converter
type: SimpleFile type: SimpleFile
...@@ -9,4 +12,11 @@ ExperimentalData: # name of the converter ...@@ -9,4 +12,11 @@ ExperimentalData: # name of the converter
records: records:
Experiment: Experiment:
date: 20$year-$month-$day date: 20$year-$month-$day
ExperimentSeries:
Experiment: $Experiment
Project:
Experiments: +$Experiment
dates: +20$year-$month-$day
...@@ -40,6 +40,15 @@ def crawler(): ...@@ -40,6 +40,15 @@ def crawler():
def test_substitutions(crawler): def test_substitutions(crawler):
subd = crawler.debug_tree[dircheckstr("File", "ExperimentalData", "220512_data.dat")] for i in range(2):
subd[1]["Experiment"].get_property("date") == "2022-05-12" subd = crawler.debug_tree[dircheckstr("File", "ExperimentalData", "220512_data.dat")]
subd[1]["Experiment"].get_property("date") == "2022-05-12" assert subd[i]["Experiment"].get_property("date").value == "2022-05-12"
assert isinstance(subd[i]["ExperimentSeries"].get_property("Experiment").value, db.Record)
subd = crawler.debug_tree[dircheckstr("Directory", "ExperimentalData")]
assert subd[i]["Project"].name == "project"
assert isinstance(subd[i]["Project"].get_property("Experiments").value, list)
assert isinstance(subd[i]["Project"].get_property("Experiments").value[0], db.Record)
assert isinstance(subd[i]["Project"].get_property("dates").value, list)
assert subd[i]["Project"].get_property("dates").value[0] == "2022-05-12"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment