#!/usr/bin/env python from __future__ import print_function from argparse import ArgumentParser import json, os, re from urllib import urlencode from urllib2 import urlopen, HTTPError, URLError from jinja2 import FileSystemLoader, Environment def group (items, key=lambda x: x): ret = [] keys = {} for item in items: k = key(item) if k not in keys: keys[k] = [] keys[k].append(item) for k in sorted(keys): keys[k].sort() ret.append(keys[k]) return ret def main(args): p = ArgumentParser("") p.add_argument("input", nargs="+", help="filenames") p.add_argument("--templates", default=None, help="templates path") args = p.parse_args(args) tmpath = args.templates if tmpath == None: tmpath = os.path.split(os.path.abspath(__file__))[0] tmpath = os.path.split(tmpath)[0] tmpath = os.path.join(tmpath, "data", "templates") env = Environment(loader=FileSystemLoader(tmpath)) template = env.get_template("pad_index.html") inputs = args.input inputs.sort() inputs = [x for x in inputs if os.path.isdir(x)] def base (x): return re.sub(r"(\.html)|(\.diff\.html)|(\.meta\.json)|(\.txt)$", "", x) # TODO: MODIFY THIS TO MAKE THE OUTPUT JOINABLE with the collected META DATA # evt: how can the metadata become a GRAPH structure!!! with each output DOCUMENT # print ("
    ") for x in inputs: padid = x metapath = os.path.join(x, "{0}.meta.json".format(padid)) if os.path.exists(metapath): print ("""
  1. {0}
  2. """.format(x)) with open(metapath) as f: meta = json.load(f) indexpath = os.path.join(x, "index.html") with open(indexpath, "w") as f: print (template.render(**meta).encode("utf-8"), file=f) print ("
")