File: copy-licences.py

package info (click to toggle)
eccodes-python 2%3A2.43.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 2,816 kB
  • sloc: python: 3,518; ansic: 277; sh: 94; makefile: 81; cpp: 30
file content (133 lines) | stat: -rw-r--r-- 3,550 bytes parent folder | download | duplicates (2)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/usr/bin/env python
#
# (C) Copyright 2024- ECMWF.
#
# This software is licensed under the terms of the Apache Licence Version 2.0
# which can be obtained at http://www.apache.org/licenses/LICENSE-2.0.
#
# In applying this licence, ECMWF does not waive the privileges and immunities
# granted to it by virtue of its status as an intergovernmental organisation nor
# does it submit to any jurisdiction.
#

import json
import re
import sys

import requests
from html2text import html2text


def identity(x):
    return x


ENTRIES = {
    "libeccodes": {
        "home": "https://github.com/ecmwf/eccodes",
        "copying": "https://raw.githubusercontent.com/ecmwf/eccodes/develop/LICENSE",
    },
    "libpng": {
        "home": "https://github.com/glennrp/libpng",
        "copying": "https://raw.githubusercontent.com/glennrp/libpng/libpng16/LICENSE",
    },
    "libaec": {
        "home": "https://github.com/MathisRosenhauer/libaec",
        "copying": "https://raw.githubusercontent.com/MathisRosenhauer/libaec/master/LICENSE.txt",
    },
    "libjasper": {
        "home": "https://github.com/jasper-software/jasper",
        "copying": "https://raw.githubusercontent.com/jasper-software/jasper/master/LICENSE.txt",
    },
    "libopenjp2": {
        "home": "https://github.com/uclouvain/openjpeg",
        "copying": "https://raw.githubusercontent.com/uclouvain/openjpeg/master/LICENSE",
    },
    "libopenjpeg": {
        "home": "https://code.google.com/archive/p/openjpeg/",
        "copying": "https://raw.githubusercontent.com/uclouvain/openjpeg/master/LICENSE",
    },
    "libjpeg": {
        "home": "http://ijg.org",
        "copying": "https://jpegclub.org/reference/libjpeg-license/",
        "html": True,
    },
    "libzlib1": {
        "home": "https://www.zlib.net/",
        "copying": "https://www.zlib.net/zlib_license.html",
        "html": True,
    },
}

PATTERNS = {
    r"^libpng\d+$": "libpng",
    r"^libproj(_\d+)+$": "libproj",
}

ALIASES = {
    "libeccodes_memfs": "libeccodes",
}

if False:
    for e in ENTRIES.values():
        if isinstance(e, dict):
            copying = e["copying"]
            if copying.startswith("http"):
                requests.head(copying).raise_for_status()

libs = {}
missing = []
seen = set()

for line in open(sys.argv[1], "r"):  # noqa: C901
    lib = "-no-regex-"
    lib = line.strip().split("/")[-1]
    lib = lib.split("-")[0].split(".")[0]

    if lib == "":
        continue

    if not lib.startswith("lib"):
        lib = f"lib{lib}"

    for k, v in PATTERNS.items():
        if re.match(k, lib):
            lib = v

    lib = ALIASES.get(lib, lib)

    if lib not in ENTRIES:
        missing.append((lib, line))
        continue

    if lib in seen:
        continue

    seen.add(lib)

    e = ENTRIES[lib]
    if e is None:
        continue

    libs[lib] = dict(path=f"copying/{lib}.txt", home=e["home"])
    copying = e["copying"]

    filtering = identity
    if e.get("html"):
        filtering = html2text

    with open(f"eccodes/copying/{lib}.txt", "w") as f:
        if copying.startswith("http://") or copying.startswith("https://"):
            r = requests.get(copying)
            r.raise_for_status()
            for n in filtering(r.text).split("\n"):
                print(n, file=f)
        else:
            for n in copying.split("\n"):
                print(n, file=f)

    with open("eccodes/copying/list.json", "w") as f:
        print(json.dumps(libs), file=f)


assert len(missing) == 0, json.dumps(missing, indent=4, sort_keys=True)