Skip to content
Snippets Groups Projects
Commit 364cd5ad authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

Merge branch 'f-real-path' into f-prefix

parents e2b47e64 75548ffe
No related branches found
No related tags found
2 merge requests!105REL: v0.4.0,!101ENH: add the 'add_prefix' argument
Pipeline #33875 passed
...@@ -25,8 +25,8 @@ extroot: ...@@ -25,8 +25,8 @@ extroot:
parents: parents:
- mdfile - mdfile
role: File role: File
path: $DataFile_path path: ${DataFile.path}
file: $DataFile_path file: ${DataFile.path}
Experiment: Experiment:
mdfile: $mdfile mdfile: $mdfile
...@@ -68,8 +68,8 @@ extroot: ...@@ -68,8 +68,8 @@ extroot:
parents: parents:
- mdfile - mdfile
role: File role: File
path: $DataFile_path path: ${DataFile.path}
file: $DataFile_path file: ${DataFile.path}
Experiment: {} Experiment: {}
......
...@@ -56,6 +56,10 @@ SPECIAL_PROPERTIES = ("description", "name", "id", "path", ...@@ -56,6 +56,10 @@ SPECIAL_PROPERTIES = ("description", "name", "id", "path",
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
class CrawlerTemplate(Template):
braceidpattern = r"(?a:[_a-z][_\.a-z0-9]*)"
def _only_max(children_with_keys): def _only_max(children_with_keys):
return [max(children_with_keys, key=lambda x: x[1])[0]] return [max(children_with_keys, key=lambda x: x[1])[0]]
...@@ -119,7 +123,7 @@ def create_path_value(func): ...@@ -119,7 +123,7 @@ def create_path_value(func):
def inner(self, values: GeneralStore, element: StructureElement): def inner(self, values: GeneralStore, element: StructureElement):
func(self, values=values, element=element) func(self, values=values, element=element)
values.update({self.name + "_path": element.path}) values.update({self.name + ".path": element.path})
return inner return inner
...@@ -146,7 +150,7 @@ def replace_variables(propvalue, values: GeneralStore): ...@@ -146,7 +150,7 @@ def replace_variables(propvalue, values: GeneralStore):
if isinstance(values[varname], db.Entity): if isinstance(values[varname], db.Entity):
return values[varname] return values[varname]
propvalue_template = Template(propvalue) propvalue_template = CrawlerTemplate(propvalue)
return propvalue_template.safe_substitute(**values.get_storage()) return propvalue_template.safe_substitute(**values.get_storage())
...@@ -254,7 +258,7 @@ def create_records(values: GeneralStore, records: RecordStore, def_records: dict ...@@ -254,7 +258,7 @@ def create_records(values: GeneralStore, records: RecordStore, def_records: dict
continue continue
# Allow replacing variables in keys / names of properties: # Allow replacing variables in keys / names of properties:
key_template = Template(key) key_template = CrawlerTemplate(key)
key = key_template.safe_substitute(**values.get_storage()) key = key_template.safe_substitute(**values.get_storage())
keys_modified.append((name, key)) keys_modified.append((name, key))
......
...@@ -183,8 +183,10 @@ Automatically generated keys ...@@ -183,8 +183,10 @@ Automatically generated keys
Some variable names are automatically generated and can be used using the Some variable names are automatically generated and can be used using the
``$<variable name>`` syntax. Those include: ``$<variable name>`` syntax. Those include:
- ``<converter name>``: access the path of converter names to the current converter - ``<converter name>``: access the path of converter names to the current converter
- ``<converter name>_path``: the file system path to the structure element - ``<converter name>.path``: the file system path to the structure element
(file system related converters only) (file system related converters only; you need curly brackets to use them:
``${<converter name>.path}``)
- ``<Record key>``: all entities that are created in the ``records`` section - ``<Record key>``: all entities that are created in the ``records`` section
are available under the same key are available under the same key
...@@ -22,7 +22,7 @@ Data: # name of the converter ...@@ -22,7 +22,7 @@ Data: # name of the converter
parents: parents:
- Project # not needed as the name is equivalent - Project # not needed as the name is equivalent
date: $date date: $date
identifier: $identifier identifier: ${identifier}
subtree: subtree:
measurement: # new name for folders on the 3rd level measurement: # new name for folders on the 3rd level
......
...@@ -619,5 +619,5 @@ def test_create_path_value(converter_registry): ...@@ -619,5 +619,5 @@ def test_create_path_value(converter_registry):
name="Test", converter_registry=converter_registry) name="Test", converter_registry=converter_registry)
values = GeneralStore() values = GeneralStore()
dc.create_values(values, Directory("a", "/a")) dc.create_values(values, Directory("a", "/a"))
assert "Test_path" in values assert "Test.path" in values
assert values["Test_path"] == "/a" assert values["Test.path"] == "/a"
...@@ -50,8 +50,8 @@ def test_record_structure_generation(crawler): ...@@ -50,8 +50,8 @@ def test_record_structure_generation(crawler):
subdRTGPL = subd[0] subdRTGPL = subd[0]
assert len(subddata) == 5 assert len(subddata) == 5
assert "DataAnalysis" in subddata assert "DataAnalysis" in subddata
assert "DataAnalysis_path" in subddata assert "DataAnalysis.path" in subddata
assert "Data_path" in subddata assert "Data.path" in subddata
assert "RecordThatGetsParentsLater" in subddata assert "RecordThatGetsParentsLater" in subddata
prop = subddata["RecordThatGetsParentsLater"].get_property("someId") prop = subddata["RecordThatGetsParentsLater"].get_property("someId")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment