#!/usr/bin/env python3
"""
Generate logos from logo-config.toml
Edit the config file in VS Code, then run this script
"""
import sys
from pathlib import Path
try:
import tomli
except ImportError:
print("ā tomli not installed. Installing...")
import subprocess
subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'tomli'])
import tomli
def create_svg_defs():
"""Standard gradients and filters"""
return '''
'''
def element_to_svg(elem):
"""Convert element dict to SVG tag"""
elem_type = elem.pop('type')
# Handle special cases
if 'filter' in elem and elem['filter'] == 'glow':
elem['filter'] = 'url(#glow)'
# Build attributes string
attrs = ' '.join(f'{k.replace("_", "-")}="{v}"' for k, v in elem.items() if k != 'content')
# Return appropriate tag
if elem_type == 'text':
content = elem.get('content', '')
return f' {content}'
elif elem_type in ['circle', 'rect', 'line']:
return f' <{elem_type} {attrs}/>'
elif elem_type in ['path', 'polygon']:
return f' <{elem_type} {attrs}/>'
else:
return f' '
def generate_logo(logo_config):
"""Generate SVG from logo config"""
width = logo_config.get('width', 200)
height = logo_config.get('height', 200)
name = logo_config.get('name', 'logo')
svg = f''
return svg
def main():
config_file = Path('logo-config.toml')
if not config_file.exists():
print(f"ā Config file not found: {config_file}")
print("Create logo-config.toml first!")
return
print("šØ Reading logo configuration...\n")
with open(config_file, 'rb') as f:
config = tomli.load(f)
if 'logo' not in config:
print("ā No [[logo]] sections found in config")
return
logos = config['logo']
if not isinstance(logos, list):
logos = [logos]
print(f"Found {len(logos)} logo(s) to generate\n")
for logo_config in logos:
name = logo_config.get('name', 'unnamed')
output_path = Path(logo_config.get('output', f'assets/{name}.svg'))
# Ensure output directory exists
output_path.parent.mkdir(parents=True, exist_ok=True)
# Generate SVG
svg_content = generate_logo(logo_config)
# Write to file
output_path.write_text(svg_content)
element_count = len(logo_config.get('elements', []))
print(f"ā {name}")
print(f" āā {output_path} ({element_count} elements)")
print(f"\nā
Generated {len(logos)} logo(s)!")
print("\nTo modify logos:")
print("1. Edit logo-config.toml in VS Code")
print("2. Run: python3 tools/generate_from_config.py")
print("3. View: xdg-open assets/logo.svg")
if __name__ == '__main__':
main()