paulo@48: import os paulo@48: import stat paulo@48: import datetime paulo@48: paulo@48: import html paulo@48: paulo@48: paulo@55: def read_indexroot(indexroot_fn): paulo@55: ret = '' paulo@55: with open(indexroot_fn) as f: paulo@55: try: paulo@55: ret = f.next().strip() paulo@55: except StopIteration: paulo@55: pass paulo@55: return ret paulo@48: paulo@48: paulo@48: def main(environ): paulo@48: dirs = [] paulo@48: paulo@48: for i in os.listdir("."): paulo@55: indexroot_fn = os.path.join(i, "_indexroot") paulo@55: if i[0] != '.' and os.path.isdir(i) and os.path.exists(indexroot_fn): paulo@48: statobj = os.stat(i) paulo@55: if not (statobj.st_mode & stat.S_IXOTH) and (statobj.st_mode & stat.S_IROTH): paulo@55: continue paulo@55: indexroot_statobj = os.stat(indexroot_fn) paulo@55: mtime = datetime.datetime.fromtimestamp(indexroot_statobj.st_mtime) paulo@55: indexroot = read_indexroot(indexroot_fn) paulo@55: dirs.append((i, mtime, indexroot)) paulo@48: paulo@48: root = html.HTML("html") paulo@55: title = "-[pauloang.com]-" paulo@48: paulo@96: header = root.head paulo@48: header.title(title) paulo@48: header.link(rel="stylesheet", type="text/css", href="index.css") paulo@48: paulo@55: body = root.body(klass="body") paulo@55: body.h1(title, escape=False) paulo@48: paulo@55: for (i, mtime, indexroot) in sorted(dirs, key=lambda x: x[1], reverse=True): paulo@55: body.a(i, href=os.path.join(i, indexroot)) paulo@55: body.br paulo@48: paulo@55: body.div(klass="email").p.a("pbba13@gmail.com", href="mailto:pbba13@gmail.com") paulo@55: paulo@48: return unicode(root).encode("utf-8") paulo@48: paulo@48: paulo@48: def app(environ, start_response): paulo@48: response_body = main(environ) paulo@48: response_headers = [ paulo@48: ("Content-Type", "text/html; charset=UTF-8"), paulo@48: ("Content-Length", str(len(response_body))), paulo@48: ] paulo@48: start_response("200 OK", response_headers) paulo@48: paulo@48: return [response_body]