Mercurial > hg > index.fcgi > www > www-1
comparison index_app.py @ 57:b7966ae653f2
pics2: add support for .webm files; add pics.fcgi and index.css
author | paulo |
---|---|
date | Tue, 14 Jan 2014 23:44:24 -0800 |
parents | 637a4470363b |
children | 259a484f691b |
comparison
equal
deleted
inserted
replaced
1:4a60cd7041dc | 2:73411b5df952 |
---|---|
3 import datetime | 3 import datetime |
4 | 4 |
5 import html | 5 import html |
6 | 6 |
7 | 7 |
8 def _get_cwd(environ): | 8 def read_indexroot(indexroot_fn): |
9 ROOTPATH = "pauloang.com" | 9 ret = '' |
10 path_info = environ.get("PATH_INFO", '') | 10 with open(indexroot_fn) as f: |
11 return [ROOTPATH] + [i for i in path_info.split('/') if len(i) > 0] | 11 try: |
12 | 12 ret = f.next().strip() |
13 | 13 except StopIteration: |
14 def _get_breadcrumb(cwd): | 14 pass |
15 h = html.HTML() | 15 return ret |
16 for (i, d) in enumerate(cwd[:-1]): | |
17 h.a(d, href='/' + '/'.join(cwd[1:i+1])) | |
18 h.text('/') | |
19 h.text(cwd[-1]) | |
20 return h | |
21 | 16 |
22 | 17 |
23 def main(environ): | 18 def main(environ): |
24 cwd = _get_cwd(environ) | |
25 dirs = [] | 19 dirs = [] |
26 | 20 |
27 for i in os.listdir("."): | 21 for i in os.listdir("."): |
28 if i[0] != '.' and os.path.isdir(i): | 22 indexroot_fn = os.path.join(i, "_indexroot") |
23 if i[0] != '.' and os.path.isdir(i) and os.path.exists(indexroot_fn): | |
29 statobj = os.stat(i) | 24 statobj = os.stat(i) |
30 mtime = datetime.datetime.fromtimestamp(statobj.st_mtime) | 25 if not (statobj.st_mode & stat.S_IXOTH) and (statobj.st_mode & stat.S_IROTH): |
31 modeok = (statobj.st_mode & stat.S_IXOTH) and (statobj.st_mode & stat.S_IROTH) | 26 continue |
32 dirs.append((i, modeok, mtime)) | 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)) | |
33 | 31 |
34 root = html.HTML("html") | 32 root = html.HTML("html") |
35 TITLE_FMT = "-[%s]-" | 33 title = "-[pauloang.com]-" |
36 title = TITLE_FMT % '/'.join(cwd) | |
37 | 34 |
38 header = root.header | 35 header = root.header |
39 header.title(title) | 36 header.title(title) |
40 header.link(rel="stylesheet", type="text/css", href="index.css") | 37 header.link(rel="stylesheet", type="text/css", href="index.css") |
41 | 38 |
42 body = root.body | 39 body = root.body(klass="body") |
43 body.h1(TITLE_FMT % str(_get_breadcrumb(cwd)), escape=False) | 40 body.h1(title, escape=False) |
44 | 41 |
45 body_table = body.table(klass="index") | 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 | 45 |
47 for (i, modeok, mtime) in sorted(dirs, key=lambda x: x[2], reverse=True): | 46 body.div(klass="email").p.a("pbba13@gmail.com", href="mailto:pbba13@gmail.com") |
48 if modeok: | 47 |
49 r = body_table.tr | |
50 r.td.div(mtime.isoformat(), klass="index_date") | |
51 r.td.a(i, href=i) | |
52 | |
53 return unicode(root).encode("utf-8") | 48 return unicode(root).encode("utf-8") |
54 | 49 |
55 | 50 |
56 def app(environ, start_response): | 51 def app(environ, start_response): |
57 response_body = main(environ) | 52 response_body = main(environ) |