merge
authorTero Marttila <terom@fixme.fi>
Thu, 07 Jan 2010 22:25:05 +0200
changeset 44 1a93b5a6efd0
parent 43 fcd818eb5a71 (current diff)
parent 42 a5bca7b0cd8a (diff)
child 45 0ce4064c428e
merge
pngtile/wsgi.py
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/pngtile.fcgi	Thu Jan 07 22:25:05 2010 +0200
@@ -0,0 +1,34 @@
+#!/usr/bin/env python2.5
+
+import flup.server.fcgi
+
+def main (app, bind=None) :
+    """
+        Run as a non-threaded single-process non-multiplexed FastCGI server
+    """
+
+    # create WSGIServer
+    server = flup.server.fcgi.WSGIServer(app, 
+        # try to supress threading
+        multithreaded=False, 
+        multiprocess=False, 
+        multiplexed=False,
+        
+        # specify the bind() address
+        bindAddress=bind,
+
+        # leave as defaults for now
+        umask=None,
+
+        # XXX: non-debug mode?
+        debug=True,
+    )
+    
+    # run... threads :(
+    server.run()
+
+if __name__ == '__main__' :
+    import pngtile.wsgi
+
+    main(pngtile.wsgi.application)
+
--- a/pngtile/wsgi.py	Thu Jan 07 22:24:30 2010 +0200
+++ b/pngtile/wsgi.py	Thu Jan 07 22:25:05 2010 +0200
@@ -4,11 +4,11 @@
 
 from werkzeug import Request, Response, responder
 from werkzeug import exceptions
-import os.path
+import os.path, os
 
 import pypngtile as pt
 
-DATA_ROOT = os.path.abspath('data')
+DATA_ROOT = os.environ.get("PNGTILE_DATA_PATH") or os.path.abspath('data/')
 
 IMAGE_CACHE = {}
 
@@ -20,6 +20,7 @@
 
 def dir_view (req, name, path) :
     prefix = os.path.dirname(req.script_root).rstrip('/')
+    script_prefix = req.script_root
     name = name.rstrip('/')
 
 
@@ -42,9 +43,9 @@
         
         listing         = "\n".join(
             """<li><a href="%(url)s">%(name)s</a></li>""" % dict(
-                url         = '/'.join((prefix, name, item)),
+                url         = '/'.join((script_prefix, name, item)),
                 name        = item,
-            ) for item in ['..'] + os.listdir(path)
+            ) for item in ['..'] + [i for i in os.listdir(path) if i.endswith('.png') or os.path.isdir(os.path.join(path, i))]
         ),
     )
 
@@ -130,6 +131,7 @@
     
     # build absolute path
     image_path = os.path.abspath(os.path.join(DATA_ROOT, image_name))
+
     
     # ensure the path points inside the data root
     if not image_path.startswith(DATA_ROOT) :