diff --git a/integrationtests/test_data/extroot/use_case_simple_presentation/cfood.yml b/integrationtests/test_data/extroot/use_case_simple_presentation/cfood.yml index 3cf6124dedf2300fe82265de36b0be2bb070e77d..c55be2157a1f079ecfb5809c3658586f9114fad1 100644 --- a/integrationtests/test_data/extroot/use_case_simple_presentation/cfood.yml +++ b/integrationtests/test_data/extroot/use_case_simple_presentation/cfood.yml @@ -25,8 +25,8 @@ extroot: parents: - mdfile role: File - path: $DataFile_path - file: $DataFile_path + path: ${DataFile.path} + file: ${DataFile.path} Experiment: mdfile: $mdfile @@ -68,8 +68,8 @@ extroot: parents: - mdfile role: File - path: $DataFile_path - file: $DataFile_path + path: ${DataFile.path} + file: ${DataFile.path} Experiment: {} diff --git a/src/caoscrawler/converters.py b/src/caoscrawler/converters.py index e359be4f30bf971ecfe06de343cae69bb2d29ef2..1962737dddbe71869846bcd40ecd8b0905ef0907 100644 --- a/src/caoscrawler/converters.py +++ b/src/caoscrawler/converters.py @@ -56,6 +56,10 @@ SPECIAL_PROPERTIES = ("description", "name", "id", "path", logger = logging.getLogger(__name__) +class CrawlerTemplate(Template): + braceidpattern = r"(?a:[_a-z][_\.a-z0-9]*)" + + def _only_max(children_with_keys): return [max(children_with_keys, key=lambda x: x[1])[0]] @@ -119,7 +123,7 @@ def create_path_value(func): def inner(self, values: GeneralStore, element: StructureElement): func(self, values=values, element=element) - values.update({self.name + "_path": element.path}) + values.update({self.name + ".path": element.path}) return inner @@ -146,7 +150,7 @@ def replace_variables(propvalue, values: GeneralStore): if isinstance(values[varname], db.Entity): return values[varname] - propvalue_template = Template(propvalue) + propvalue_template = CrawlerTemplate(propvalue) return propvalue_template.safe_substitute(**values.get_storage()) @@ -254,7 +258,7 @@ def create_records(values: GeneralStore, records: RecordStore, def_records: dict continue # Allow replacing variables in keys / names of properties: - key_template = Template(key) + key_template = CrawlerTemplate(key) key = key_template.safe_substitute(**values.get_storage()) keys_modified.append((name, key)) diff --git a/unittests/scifolder_cfood.yml b/unittests/scifolder_cfood.yml index 74fd027563907c5ae416ca389faba0ecd64d5848..dce219b751c3e980662a1eaa4904e1163d9836a0 100644 --- a/unittests/scifolder_cfood.yml +++ b/unittests/scifolder_cfood.yml @@ -22,7 +22,7 @@ Data: # name of the converter parents: - Project # not needed as the name is equivalent date: $date - identifier: $identifier + identifier: ${identifier} subtree: measurement: # new name for folders on the 3rd level diff --git a/unittests/test_converters.py b/unittests/test_converters.py index c1ca9ea03c8631678f5b67cad3c33685a16cfd32..4d3791fce3ceffaafe529423e4020ebd6a4231ba 100644 --- a/unittests/test_converters.py +++ b/unittests/test_converters.py @@ -619,5 +619,5 @@ def test_create_path_value(converter_registry): name="Test", converter_registry=converter_registry) values = GeneralStore() dc.create_values(values, Directory("a", "/a")) - assert "Test_path" in values - assert values["Test_path"] == "/a" + assert "Test.path" in values + assert values["Test.path"] == "/a" diff --git a/unittests/test_scalars_cfood.py b/unittests/test_scalars_cfood.py index 5780219c0f3bab44f383b38fbcd9999e38acfbf2..ac408b2dab0fa151c370d3ec6ffd1dced22c77d7 100644 --- a/unittests/test_scalars_cfood.py +++ b/unittests/test_scalars_cfood.py @@ -50,8 +50,8 @@ def test_record_structure_generation(crawler): subdRTGPL = subd[0] assert len(subddata) == 5 assert "DataAnalysis" in subddata - assert "DataAnalysis_path" in subddata - assert "Data_path" in subddata + assert "DataAnalysis.path" in subddata + assert "Data.path" in subddata assert "RecordThatGetsParentsLater" in subddata prop = subddata["RecordThatGetsParentsLater"].get_property("someId")