#!/usr/bin/env python3 import glob import json import os import shutil import toml def get_features(dirname): features = {} for feature in sorted(os.listdir('caniuse.rs/data/' + dirname)): with open('caniuse.rs/data/' + dirname + '/' + feature) as f: name = feature.split('.')[0] features[name] = toml.load(f) return features with open('caniuse.rs/data/versions.toml') as f: versions = toml.load(f) for version, data in versions.items(): try: data['features'] = get_features(version) except FileNotFoundError: pass unstable_features = get_features('unstable') os.makedirs('target', exist_ok=True) shutil.copy('style.css', 'target') with open('target/data.json', 'w') as f: json.dump(dict(unstable=unstable_features, versions=versions), f) def write_features(f, features): f.write('') with open('target/index.html', 'w') as f: f.write('') f.write('') f.write('Rust features') f.write('

Rust features

') f.write('') # TODO: sort by T-lang and T-lib f.write('

Unstable features

') write_features(f, unstable_features) for version, data in reversed(list(versions.items())): f.write('

{}

'.format(version)) if 'features' in data: write_features(f, data['features']) # TODO: generate HTML