#! /usr/bin/env python3 import os import shutil import optparse import config p = optparse.OptionParser() p.add_option('-p', '--puzzles', dest='puzzles', default='puzzles', help='Directory containing puzzles') p.add_option('-w', '--htmldir', dest='htmldir', default='puzzler', help='Directory to write HTML puzzle tree') p.add_option('-k', '--keyfile', dest='keyfile', default='puzzler.keys', help='Where to write keys') opts, args = p.parse_args() keys = [] for cat in os.listdir(opts.puzzles): dirname = os.path.join(opts.puzzles, cat) for points in os.listdir(dirname): pointsdir = os.path.join(dirname, points) outdir = os.path.join(opts.htmldir, cat, points) os.makedirs(outdir) readme = '' files = [] for fn in os.listdir(pointsdir): path = os.path.join(pointsdir, fn) if fn == 'key': key = open(path, encoding='utf-8').readline().strip() keys.append((cat, points, key)) elif fn == 'index.html': readme = open(path, encoding='utf-8').read() else: files.append((fn, path)) title = '%s for %s points' % (cat, points) f = open(os.path.join(outdir, 'index.html'), 'w', encoding='utf-8') f.write('''