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:
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: {}
......
......@@ -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))
......
......@@ -183,8 +183,10 @@ Automatically generated keys
Some variable names are automatically generated and can be used using the
``$<variable name>`` syntax. Those include:
- ``<converter name>``: access the path of converter names to the current converter
- ``<converter name>_path``: the file system path to the structure element
(file system related converters only)
- ``<converter name>.path``: the file system path to the structure element
(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
are available under the same key
......@@ -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
......
......@@ -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"
......@@ -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")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment