get DATA_ROOT from os.environ, fix use of prefix for dir view
authorTero Marttila <terom@fixme.fi>
Wed, 06 Jan 2010 18:35:49 +0200
changeset 42 a5bca7b0cd8a
parent 41 941090e3d094
child 44 1a93b5a6efd0
get DATA_ROOT from os.environ, fix use of prefix for dir view
bin/pngtile.fcgi
pngtile/wsgi.py
--- a/bin/pngtile.fcgi	Wed Jan 06 18:20:01 2010 +0200
+++ b/bin/pngtile.fcgi	Wed Jan 06 18:35:49 2010 +0200
@@ -1,3 +1,5 @@
+#!/usr/bin/env python2.5
+
 import flup.server.fcgi
 
 def main (app, bind=None) :
--- a/pngtile/wsgi.py	Wed Jan 06 18:20:01 2010 +0200
+++ b/pngtile/wsgi.py	Wed Jan 06 18:35:49 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 = {}
 
@@ -17,6 +17,7 @@
 
 def dir_view (req, name, path) :
     prefix = os.path.dirname(req.script_root).rstrip('/')
+    script_prefix = req.script_root
     name = name.rstrip('/')
 
 
@@ -39,9 +40,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))]
         ),
     )
 
@@ -118,6 +119,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) :