1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45
|
from tlz import filter
from tlz.functoolz import compose_left, curry
from tlz.itertoolz import concat, get
from safe_rcm.product.dicttoolz import query
from safe_rcm.xml import read_xml
def merge_location(loc):
locator = loc["@locator"]
href = loc["@href"]
return f"{locator}/{href}".lstrip("/")
def read_manifest(mapper, path):
structure = {
"/dataObjectSection/dataObject": compose_left(
curry(
map,
compose_left(
curry(get, "byteStream"),
curry(
map,
compose_left(
curry(get, "fileLocation"), curry(map, merge_location)
),
),
concat,
),
),
concat,
),
"/metadataSection/metadataObject": compose_left(
curry(
filter,
compose_left(curry(get, "@classification"), lambda x: x == "SYNTAX"),
),
curry(map, compose_left(curry(get, "metadataReference"), merge_location)),
),
}
manifest = read_xml(mapper, path)
return list(concat(func(query(path, manifest)) for path, func in structure.items()))
|