File: manifest.py

package info (click to toggle)
xarray-safe-rcm 2024.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 212 kB
  • sloc: python: 1,082; sh: 23; makefile: 4
file content (45 lines) | stat: -rw-r--r-- 1,290 bytes parent folder | download
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()))