Files
2026-09-01 10:46:29 -03:00

56 lines
1.8 KiB
Python
Executable File

import json
import os
LOCK_FILE = 'composer.lock'
OUTPUT_FILE = 'THIRD-PARTY-LICENSES.txt'
def main():
if not os.path.exists(LOCK_FILE):
print(f"Error: {LOCK_FILE} not found.")
return
try:
with open(LOCK_FILE, 'r', encoding='utf-8') as f:
data = json.load(f)
except Exception as e:
print(f"Error reading {LOCK_FILE}: {e}")
return
packages = data.get('packages', [])
packages_dev = data.get('packages-dev', [])
# Combine all packages
all_packages = packages + packages_dev
# Sort by name
all_packages.sort(key=lambda x: x.get('name', '').lower())
with open(OUTPUT_FILE, 'w', encoding='utf-8') as f:
f.write("THIRD-PARTY SOFTWARE NOTICES AND INFORMATION\n")
f.write("============================================\n\n")
f.write("This software includes the following third-party software components:\n\n")
for pkg in all_packages:
name = pkg.get('name', 'Unknown')
version = pkg.get('version', 'Unknown')
licenses = pkg.get('license', [])
license_str = ', '.join(licenses) if licenses else 'Unknown'
# Try to find a URL
url = pkg.get('source', {}).get('url', '')
if not url:
url = pkg.get('dist', {}).get('url', '')
f.write(f"Package: {name}\n")
f.write(f"Version: {version}\n")
f.write(f"License: {license_str}\n")
if url:
f.write(f"URL: {url}\n")
f.write("-" * 80 + "\n")
print(f"Successfully generated {OUTPUT_FILE} with {len(all_packages)} packages.")
if __name__ == '__main__':
main()