|
|
|
#!/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
|
|
|
|
from datetime import datetime
|
|
|
|
|
|
|
|
|
|
|
|
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("index.html")
|
|
|
|
|
|
|
|
def base (x):
|
|
|
|
return re.sub(r"(\.raw\.html)|(\.diff\.html)|(\.meta\.json)|(\.raw\.txt)$", "", x)
|
|
|
|
|
|
|
|
inputs = args.input
|
|
|
|
inputs.sort()
|
|
|
|
inputs = group(inputs, base)
|
|
|
|
|
|
|
|
def loadmeta(paths):
|
|
|
|
for p in paths:
|
|
|
|
if p.endswith(".meta.json"):
|
|
|
|
with open(p) as f:
|
|
|
|
return json.load(f)
|
|
|
|
|
|
|
|
inputs = map(loadmeta, inputs)
|
|
|
|
# sort by last edited (reverse)
|
|
|
|
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
|
|
|
print (template.render({"timestamp": timestamp, "pads": inputs}).encode("utf-8"))
|
|
|
|
|
|
|
|
# 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 ("<ol>")
|
|
|
|
# for x in inputs:
|
|
|
|
# padid = x
|
|
|
|
# metapath = os.path.join(x, "{0}.meta.json".format(padid))
|
|
|
|
# if os.path.exists(metapath):
|
|
|
|
# print ("""<li><a href="{0}">{0}</a></li>""".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 ("</ol>")
|