mirror of
https://gh.wpcy.net/https://github.com/WeblateOrg/weblate.git
synced 2026-05-02 17:58:56 +08:00
84 lines
2.6 KiB
Python
Executable file
84 lines
2.6 KiB
Python
Executable file
#!/usr/bin/env python3
|
|
#
|
|
# Copyright © 2012 - 2020 Michal Čihař <michal@cihar.com>
|
|
#
|
|
# This file is part of Weblate <https://weblate.org/>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
"""
|
|
Helper script to generate Python code for licenses.
|
|
|
|
See https://github.com/spdx/license-list-data
|
|
"""
|
|
|
|
import json
|
|
import subprocess
|
|
|
|
HEADER = '''#
|
|
# Copyright © 2012 - 2020 Michal Čihař <michal@cihar.com>
|
|
#
|
|
# This file is part of Weblate <https://weblate.org/>
|
|
#
|
|
# This program is free software: you can redistribute it and/or modify
|
|
# it under the terms of the GNU General Public License as published by
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
# (at your option) any later version.
|
|
#
|
|
# This program is distributed in the hope that it will be useful,
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
# GNU General Public License for more details.
|
|
#
|
|
# You should have received a copy of the GNU General Public License
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
#
|
|
|
|
"""License data definitions.
|
|
|
|
This is an automatically generated file, see scripts/generate-license-data
|
|
"""
|
|
|
|
'''
|
|
TEMPLATE = """ (
|
|
"{0}",
|
|
"{1}",
|
|
"{2}",
|
|
{3}
|
|
),
|
|
"""
|
|
|
|
with open("scripts/spdx-license-list/json/licenses.json") as handle:
|
|
data = json.load(handle)
|
|
|
|
with open("weblate/utils/licensedata.py", "w") as output:
|
|
output.write(HEADER)
|
|
output.write("LICENSES = (\n")
|
|
for license in sorted(data["licenses"], key=lambda x: x["name"].lower()):
|
|
if license["isDeprecatedLicenseId"]:
|
|
continue
|
|
libre = license.get("isFsfLibre", False) or license["isOsiApproved"]
|
|
output.write(
|
|
TEMPLATE.format(
|
|
license["licenseId"],
|
|
license["name"].replace('"', '\\"'),
|
|
license["seeAlso"][0],
|
|
"True" if libre else "False",
|
|
)
|
|
)
|
|
output.write(")\n")
|
|
|
|
# Apply coding style
|
|
subprocess.run(["black", "weblate/utils/licensedata.py"])
|