83 lines
2.8 KiB
Python
Executable File
83 lines
2.8 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
import json
|
|
import os
|
|
import shutil
|
|
import sys
|
|
from pathlib import Path
|
|
|
|
def main():
|
|
# Read the flattened JSON file
|
|
with open('sifted_mimetypes_flattened.json', 'r') as f:
|
|
data = json.load(f)
|
|
|
|
# Create output directories
|
|
out_dir = Path('out')
|
|
icons_dir = out_dir / 'icons_breeze'
|
|
icons_dir.mkdir(parents=True, exist_ok=True)
|
|
|
|
# Copy the license file (critical, must exist)
|
|
license_source = Path('COPYING-ICONS')
|
|
shutil.copy2(license_source, out_dir / 'COPYING-ICONS')
|
|
print(f"Copied license file to {out_dir / 'COPYING-ICONS'}")
|
|
|
|
# Base directory where icons are located
|
|
icons_base = Path('icons')
|
|
|
|
for extension, icon_info in data.items():
|
|
if isinstance(icon_info, str):
|
|
# Single icon
|
|
icon_path = icon_info
|
|
elif isinstance(icon_info, list) and len(icon_info) > 0:
|
|
# Multiple icons, use the first one
|
|
icon_path = icon_info[0]
|
|
else:
|
|
print(f"Skipping invalid entry for {extension}")
|
|
continue
|
|
|
|
# Parse the icon path (format: "icon.svg:category")
|
|
if ':' in icon_path:
|
|
icon_file, category = icon_path.split(':', 1)
|
|
else:
|
|
icon_file = icon_path
|
|
category = 'common'
|
|
|
|
# Find the icon file in the icons directory
|
|
# Look in mimetypes subdirectories first
|
|
source_path = None
|
|
for size_dir in ['64']:
|
|
# for size_dir in ['16', '22', '32', '64']:
|
|
potential_path = icons_base / 'mimetypes' / size_dir / icon_file
|
|
if potential_path.exists():
|
|
source_path = potential_path
|
|
break
|
|
|
|
if source_path is None:
|
|
print(f"Warning: Icon not found for {extension}: {icon_file}")
|
|
continue
|
|
|
|
# Copy the icon to the output directory
|
|
dest_icon = icons_dir / icon_file
|
|
try:
|
|
shutil.copy2(source_path, dest_icon)
|
|
print(f"Copied {source_path} to {dest_icon}")
|
|
except Exception as e:
|
|
print(f"Error copying {source_path}: {e}")
|
|
continue
|
|
|
|
# Create symlink from extension.svg to the icon
|
|
symlink_path = out_dir / f"{extension}.svg"
|
|
try:
|
|
# Remove existing symlink if it exists
|
|
if symlink_path.exists() or symlink_path.is_symlink():
|
|
symlink_path.unlink()
|
|
|
|
# Create relative symlink
|
|
relative_target = os.path.relpath(dest_icon, symlink_path.parent)
|
|
symlink_path.symlink_to(relative_target)
|
|
print(f"Created symlink {symlink_path} -> {relative_target}")
|
|
except Exception as e:
|
|
print(f"Error creating symlink for {extension}: {e}")
|
|
|
|
if __name__ == '__main__':
|
|
main()
|