view index_app.py @ 107:24a967efbf3e

add dmd
author paulo
date Fri, 03 Apr 2020 23:58:24 -0700
parents 0fbe37b56e84
children
line source
1 import os
2 import stat
3 import datetime
5 import html
8 def read_indexroot(indexroot_fn):
9 ret = ''
10 with open(indexroot_fn) as f:
11 try:
12 ret = f.next().strip()
13 except StopIteration:
14 pass
15 return ret
18 def main(environ):
19 dirs = []
21 for i in os.listdir("."):
22 indexroot_fn = os.path.join(i, "_indexroot")
23 if i[0] != '.' and os.path.isdir(i) and os.path.exists(indexroot_fn):
24 statobj = os.stat(i)
25 if not (statobj.st_mode & stat.S_IXOTH) and (statobj.st_mode & stat.S_IROTH):
26 continue
27 indexroot_statobj = os.stat(indexroot_fn)
28 mtime = datetime.datetime.fromtimestamp(indexroot_statobj.st_mtime)
29 indexroot = read_indexroot(indexroot_fn)
30 dirs.append((i, mtime, indexroot))
32 root = html.HTML("html")
33 title = "-[pauloang.com]-"
35 header = root.head
36 header.title(title)
37 header.link(rel="stylesheet", type="text/css", href="index.css")
39 body = root.body(klass="body")
40 body.h1(title, escape=False)
42 for (i, mtime, indexroot) in sorted(dirs, key=lambda x: x[1], reverse=True):
43 body.a(i, href=os.path.join(i, indexroot))
44 body.br
46 body.div(klass="email").p.a("pbba13@gmail.com", href="mailto:pbba13@gmail.com")
48 return unicode(root).encode("utf-8")
51 def app(environ, start_response):
52 response_body = main(environ)
53 response_headers = [
54 ("Content-Type", "text/html; charset=UTF-8"),
55 ("Content-Length", str(len(response_body))),
56 ]
57 start_response("200 OK", response_headers)
59 return [response_body]