Mercurial > hg > index.fcgi > www > www-1
changeset 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 | 0249782e231e |
children | 6edb5112c804 |
files | pics2/index.css pics2/pics.fcgi pics2/pics_app.py pics2/pics_test_server.py |
diffstat | 4 files changed, 66 insertions(+), 4 deletions(-) [+] |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/pics2/index.css Tue Jan 14 23:44:24 2014 -0800 1.3 @@ -0,0 +1,20 @@ 1.4 +@import "/index.css"; 1.5 + 1.6 +img 1.7 +{ 1.8 + border-width: 0px; 1.9 +} 1.10 + 1.11 +img.sel 1.12 +{ 1.13 + padding: 2px; 1.14 + border-width: 4px; 1.15 + border-style: solid; 1.16 +} 1.17 + 1.18 +img.sel2 1.19 +{ 1.20 + padding: 2px; 1.21 + border-width: 2px; 1.22 + border-style: dashed; 1.23 +}
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/pics2/pics.fcgi Tue Jan 14 23:44:24 2014 -0800 2.3 @@ -0,0 +1,9 @@ 2.4 +#!/usr/bin/env python 2.5 + 2.6 +from flup.server.fcgi import WSGIServer 2.7 +#from flup.server.fcgi_single import WSGIServer 2.8 + 2.9 +import pics_app 2.10 + 2.11 + 2.12 +WSGIServer(pics_app.app).run()
3.1 --- a/pics2/pics_app.py Tue Sep 10 01:04:24 2013 -0700 3.2 +++ b/pics2/pics_app.py Tue Jan 14 23:44:24 2014 -0800 3.3 @@ -45,11 +45,29 @@ 3.4 3.5 3.6 def _get_images(d): 3.7 + exts = [".jpg", ".webm"] 3.8 + 3.9 thumb_fns = glob.glob(os.path.join(d, "thumbs", "*.jpg")) 3.10 thumb_fns = sorted(thumb_fns, key=_numeric_pad_basename) 3.11 logging.debug("thumb_fns = %s" % thumb_fns) 3.12 3.13 - browse_fns = [os.path.join(d, "browse", os.path.basename(i)) for i in thumb_fns] 3.14 + browse_dir = os.path.join(d, "browse") 3.15 + browse_contents = set(os.listdir(browse_dir)) 3.16 + logging.debug("browse_contents = %s" % browse_contents) 3.17 + 3.18 + browse_fns = [] 3.19 + for i in thumb_fns: 3.20 + i_basename = os.path.splitext(os.path.basename(i))[0] 3.21 + try: 3.22 + for j in exts: 3.23 + browse_fn_basename = i_basename + j 3.24 + if browse_fn_basename in browse_contents: 3.25 + browse_fns.append(os.path.join(browse_dir, browse_fn_basename)) 3.26 + raise StopIteration 3.27 + except StopIteration: 3.28 + pass 3.29 + else: 3.30 + raise RuntimeError("Cannot find browse image for %s" % i) 3.31 logging.debug("browse_fns = %s" % browse_fns) 3.32 3.33 return zip(thumb_fns, browse_fns) 3.34 @@ -88,6 +106,16 @@ 3.35 3.36 body.text(' ') 3.37 3.38 + 3.39 + def _go_browse_image_html_body(self, body, img): 3.40 + browse_img_url = self._get_pics_url(img) 3.41 + 3.42 + ext = os.path.splitext(img)[1] 3.43 + if ext == ".webm": 3.44 + body.video(src=browse_img_url, autoplay="true", loop="true") 3.45 + else: 3.46 + body.img(src=browse_img_url) 3.47 + 3.48 3.49 def __init__(self, environ): 3.50 self._environ = environ 3.51 @@ -200,8 +228,7 @@ 3.52 3.53 html_header.script('', type="text/javascript", src=self._get_pics_url("np_keys.js")) 3.54 3.55 - browse_img_url = self._get_pics_url(img) 3.56 - html_body.p.img(src=browse_img_url) 3.57 + self._go_browse_image_html_body(html_body.p, img) 3.58 3.59 logging.debug("imgs_circ = %s" % imgs_circ) 3.60
4.1 --- a/pics2/pics_test_server.py Tue Sep 10 01:04:24 2013 -0700 4.2 +++ b/pics2/pics_test_server.py Tue Jan 14 23:44:24 2014 -0800 4.3 @@ -13,13 +13,19 @@ 4.4 server.stop() 4.5 4.6 4.7 +MIMETYPE = { 4.8 + ".webm": "video/webm", 4.9 +} 4.10 + 4.11 + 4.12 class FileServerRoot: 4.13 def default(self, *args): 4.14 if len(args) == 0: 4.15 raise cherrypy.HTTPError(404) 4.16 4.17 filepath = os.path.abspath(os.path.join(*args)) 4.18 - return cherrypy.lib.static.serve_file(filepath) 4.19 + ext = os.path.splitext(filepath)[1] 4.20 + return cherrypy.lib.static.serve_file(filepath, content_type=MIMETYPE.get(ext)) 4.21 4.22 default.exposed = True 4.23