publik-base-theme/create_themes_json.py

33 lines
1016 B
Python

#! /usr/bin/env python
import argparse
import json
import os
parser = argparse.ArgumentParser()
parser.add_argument('--overlay', dest='overlay', type=str)
args = parser.parse_args()
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')))
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)
with open('themes.json', 'w') as fd:
json.dump(themes, fd, indent=2, sort_keys=True)