-
-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathapp.py
More file actions
123 lines (100 loc) · 4.08 KB
/
Copy pathapp.py
File metadata and controls
123 lines (100 loc) · 4.08 KB
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
# SPDX-License-Identifier: CC-BY-4.0 AND Apache-2.0
#
# https://github.com/nexB/scancode-licensedb
# Copyright (c) nexB Inc. and others.
# ScanCode is a trademark of nexB Inc.
#
# ScanCode LicenseDB data is licensed under the Creative Commons Attribution
# License 4.0 (CC-BY-4.0).
# Some licenses, such as the GNU GENERAL PUBLIC LICENSE, are subject to other licenses.
# See the corresponding license text for the specific license conditions.
#
# ScanCode LicenseDB software is licensed under the Apache License version 2.0.
# You may not use this software except in compliance with the License.
# You may obtain a copy of the License at: http://apache.org/licenses/LICENSE-2.0
# Unless required by applicable law or agreed to in writing, software distributed
# under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
# CONDITIONS OF ANY KIND, either express or implied. See the License for the
# specific language governing permissions and limitations under the License.
#
# ScanCode LicenseDB is generated with ScanCode Toolkit. The database and its contents
# are provided on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
# either express or implied.
# No content from ScanCode LicenseDB should be considered or used as legal advice.
# Consult an attorney for any legal advice.
#
# Visit https://github.com/nexB/scancode-licensedb for support.
#
# ScanCode Toolkit is a free Software Composition Analysis tool from nexB Inc. and
# others.
# Visit https://github.com/nexB/scancode-toolkit for support and download.
import json
import pathlib
from datetime import datetime
import saneyaml
from jinja2 import Environment, PackageLoader
from licensedcode.models import load_licenses
from scancode_config import __version__ as scancode_version
licenses = load_licenses(with_deprecated=True)
# GitHub Pages support only /(root) or docs/ for the source
BUILD_LOCATION = "docs"
env = Environment(
loader=PackageLoader("app", "templates"),
autoescape=True,
)
def write_file(path, filename, content):
path.joinpath(filename).open("w").write(content)
def now():
return datetime.now().strftime("%b %d, %Y")
base_context = {
"scancode_version": scancode_version,
"now": now(),
}
def generate_indexes(output_path):
license_list_template = env.get_template("license_list.html")
index_html = license_list_template.render(
**base_context,
licenses=licenses,
)
write_file(output_path, "index.html", index_html)
index = [
{
"license_key": key,
"spdx_license_key": license.spdx_license_key,
"other_spdx_license_keys": license.other_spdx_license_keys,
"is_exception": license.is_exception,
"is_deprecated": license.is_deprecated,
"json": f"{key}.json",
"yml": f"{key}.yml",
"html": f"{key}.html",
"text": f"{key}.LICENSE",
}
for key, license in licenses.items()
]
write_file(output_path, "index.json", json.dumps(index))
write_file(output_path, "index.yml", saneyaml.dump(index))
def generate_details(output_path):
license_details_template = env.get_template("license_details.html")
for license in licenses.values():
license_data = license.to_dict()
html = license_details_template.render(
**base_context,
license=license,
license_data=license_data,
)
write_file(output_path, f"{license.key}.html", html)
write_file(output_path, f"{license.key}.yml", saneyaml.dump(license_data))
write_file(output_path, f"{license.key}.json", json.dumps(license_data))
write_file(output_path, f"{license.key}.LICENSE", license.text)
def generate_help(output_path):
template = env.get_template("help.html")
html = template.render(**base_context)
write_file(output_path, "help.html", html)
def generate():
root_path = pathlib.Path(BUILD_LOCATION)
root_path.mkdir(parents=False, exist_ok=True)
generate_indexes(root_path)
generate_details(root_path)
generate_help(root_path)
if __name__ == "__main__":
generate()