Files
FileBow/scripts/collect-licenses.py
T

39 lines
3.3 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
from importlib import metadata
from pathlib import Path
import html
import json
import shutil
import sys
root=Path(__file__).resolve().parents[1];out=root/'licenses';out.mkdir(exist_ok=True)
packages=['pillow','pillow-heif','pypdf','cryptography','cffi','pycparser','python-docx','lxml','fpdf2','fonttools','defusedxml','typing-extensions','python-pptx','xlsxwriter','openpyxl','et-xmlfile','xlrd','striprtf','beautifulsoup4','soupsieve','packaging']
records=[]
for package in packages:
try: dist=metadata.distribution(package)
except metadata.PackageNotFoundError: continue
folder=out/'python'/package;folder.mkdir(parents=True,exist_ok=True)
files=[]
for entry in dist.files or []:
if any(word in str(entry).lower() for word in ['license','copying','copyright','notice']) and dist.locate_file(entry).is_file():
source=dist.locate_file(entry)
# Keep wheel-provided notices, including bundled codec licenses.
name=str(entry).replace('/','__').replace('\\','__')
shutil.copy2(source,folder/name);files.append(str((folder/name).relative_to(out)))
records.append({'name':dist.metadata['Name'],'version':dist.version,'license':dist.metadata.get('License-Expression') or dist.metadata.get('License') or '', 'files':files})
shutil.copy2(Path(sys.base_prefix)/'LICENSE.txt',out/'Python.txt')
shutil.copy2(root/'vendor/ffmpeg/LICENSE.txt',out/'FFmpeg-LGPL-3.0.txt')
electron=root/'node_modules/electron/dist'
for name in ['LICENSE','LICENSES.chromium.html']:
if (electron/name).exists():shutil.copy2(electron/name,out/('Electron-'+name))
(out/'components.json').write_text(json.dumps(records,indent=2,ensure_ascii=False),encoding='utf-8')
parts=['<!doctype html><html lang="de"><meta charset="utf-8"><title>FileBow – Lizenzhinweise</title><style>body{font:15px system-ui;max-width:960px;margin:40px auto;padding:24px;line-height:1.6;color:#20232a}pre{white-space:pre-wrap;overflow-wrap:anywhere;font:12px monospace}summary{cursor:pointer}a{color:#9a4518}</style><h1>FileBow – Drittanbieterkomponenten</h1><p>Die folgenden Komponenten unterliegen den Lizenzen ihrer jeweiligen Urheber. Diese Hinweise ändern keine Rechte aus diesen Lizenzen.</p><h2>FFmpeg</h2><p>FileBow verwendet FFmpeg-Bibliotheken unter der GNU LGPL Version 3. FFmpeg läuft als separater Prozess. Die dynamischen Bibliotheken liegen unverändert im Paket. Version: n9.0.2-36-g6882969ce9, BtbN LGPL shared x64. Quellcode und Buildskripte liegen im Verzeichnis <code>licenses/sources</code>.</p>']
for file in sorted(out.glob('*.txt')):
parts.append(f'<details><summary>{html.escape(file.name)}</summary><pre>{html.escape(file.read_text(encoding="utf-8",errors="replace"))}</pre></details>')
parts.append('<h2>Electron / Chromium</h2><p><a href="Electron-LICENSES.chromium.html">Chromium-Lizenzhinweise</a></p>')
for record in records:
parts.append(f'<h2>{html.escape(record["name"])} {record["version"]}</h2>')
for name in record['files']:
file=out/name
parts.append(f'<details><summary>{html.escape(file.name)}</summary><pre>{html.escape(file.read_text(encoding="utf-8",errors="replace"))}</pre></details>')
(out/'THIRD_PARTY.html').write_text('\n'.join(parts)+'</html>',encoding='utf-8')
print(f'Collected notices for {len(records)} Python distributions, Python, FFmpeg and Electron.')