#! /usr/bin/env python3 import argparse import json import os import xml.etree.ElementTree as ET parser = argparse.ArgumentParser() parser.add_argument('--overlay', dest='overlay', type=str) args = parser.parse_args() # get themes themes = [] for dirname in sorted(os.listdir('static')): config = os.path.join('static', dirname, 'config.json') if not os.path.exists(config): continue theme = json.load(open(os.path.join('static', dirname, 'config.json'), encoding='utf-8')) theme['id'] = dirname if not 'variables' in theme: theme['variables'] = {} if not theme['variables'].get('css_variant'): theme['variables']['css_variant'] = dirname if os.path.exists(os.path.join('static', dirname, 'extra.js')): theme['variables']['no_extra_js'] = False else: theme['variables']['no_extra_js'] = True if args.overlay: theme['module'] = 'publik-base' theme['overlay'] = args.overlay themes.append(theme) # get parameters parameters = {'primary-color': {'type': 'color'}} if os.path.exists('help/fr/misc-scss.page'): tree = ET.parse('help/fr/misc-scss.page') for element in tree.findall('.//{http://projectmallard.org/1.0/}tr'): name, description, value = element.findall('{http://projectmallard.org/1.0/}td') name = ''.join(name.itertext()).strip('$') description = ''.join(description.itertext()).strip('$') value = ''.join(value.itertext()).strip('$') parameter_type = 'text' if (value.startswith('#') or value in ('white', 'black') or name.endswith('color') or name.endswith('background')): parameter_type = 'color' if value.endswith('px') or value.endswith('rem') or name.endswith('size'): parameter_type = 'size' if value in ('true', 'false'): parameter_type = 'boolean' if name.endswith('weight'): parameter_type = 'weight' if name.endswith('family'): parameter_type = 'family' parameters[name] = { 'type': parameter_type, 'description': description, } with open('themes.json', 'w', encoding='utf-8') as fd: json.dump({'themes': themes, 'parameters': parameters}, fd, indent=2, sort_keys=True)