from urlparse import parse_qs
import os, TileStache
def application(environ,start_response):
params=parse_qs(environ['QUERY_STRING'])
layer=params.get('layer',[None])[0]
cfg="{\"cache\": {\"name\": \"Test\",\"path\": \"file:///tmp/stache\",\"umask\": \"0000\"},\"layers\": {\""+layer+"_mini\": {\"provider\": {\"name\": \"mapnik\",\"mapfile\": \"http://URLOfMyTilestacheServer/dynamicMapnikMiniXML.php?layer="+layer+"\"},\"projection\": \"spherical mercator\",\"bounds\": {\"north\": 89,\"west\": -180,\"south\": -89,\"east\": 180,\"low\": 0,\"high\": 40},\"png options\": {\"optimize\": true}},\""+layer+"\": {\"provider\": {\"name\": \"mapnik\",\"mapfile\": \"http://URLOfMyTilestacheServer/dynamicMapnikXML.php?layer="+layer+"\"},\"projection\": \"spherical mercator\",\"bounds\": {\"north\": 89,\"west\": -180,\"south\": -89,\"east\": 180,\"low\": 0,\"high\": 40},\"png options\": {\"optimize\": true}}}}"
f=open('/tmp/tilestache.cfg','w')
f.write(cfg)
f.close()
TileStache.WSGITileServer('/tmp/tilestache.cfg')