avid.common.artefact.crawler.crawl_property_by_filename

avid.common.artefact.crawler.crawl_property_by_filename(extraction_rules: Dict[str, Tuple[str, Any]], add_none: bool = False) Callable

Decorator to extract property values from the filename of a potential artefact.

Parameters:
  • extraction_rules – Dictionary of extraction rules for certain properties. Key indicates the property key for which a value should be captured. Value is a (regex_pattern, default_value) tuple. regex_pattern: regex with one capture group that will be used to get the value. default: fallback value if no match is found.

  • add_none – Whether to add a property with None value if no match found and default is None.

Returns:

Decorated function that applies filename-based property extraction

Example:

@crawl_property_by_filename({
    "case":(r"Case_(\w+)", "unknown"),
    "timePoint":(r"TS(\d+)", 0)
})
def file_function(path_parts, filename, full_path, *args, **kwargs):
    # do stuff

file_function(filename="Case_Pat1_TS3.txt")
# -> {'case': 'Pat1', 'timePoint': '3'}