Permalink
Browse files

Pushing internal layer configuration to a static prepareKeywordArgs()…

… method of provider classes, starting with Proxy, UrlTemplate and Sandwich providers
  • Loading branch information...
1 parent 2d8e80f commit c4e9d570e15a139c366eb14dee8e543dd7a9e67d @migurski migurski committed Sep 4, 2012
Showing with 41 additions and 17 deletions.
  1. +2 −13 TileStache/Config.py
  2. +33 −4 TileStache/Providers.py
  3. +6 −0 TileStache/Sandwich.py
View
@@ -426,17 +426,6 @@ def _parseConfigfileLayer(layer_dict, config, dirpath):
provider_kwargs['mapfile'] = provider_dict['mapfile']
provider_kwargs['fonts'] = provider_dict.get('fonts', None)
- elif _class is Providers.Proxy:
- if 'url' in provider_dict:
- provider_kwargs['url'] = provider_dict['url']
- if 'provider' in provider_dict:
- provider_kwargs['provider_name'] = provider_dict['provider']
-
- elif _class is Providers.UrlTemplate:
- provider_kwargs['template'] = provider_dict['template']
- if 'referer' in provider_dict:
- provider_kwargs['referer'] = provider_dict['referer']
-
elif _class is Providers.Vector.Provider:
provider_kwargs['driver'] = provider_dict['driver']
provider_kwargs['parameters'] = provider_dict['parameters']
@@ -472,8 +461,8 @@ def _parseConfigfileLayer(layer_dict, config, dirpath):
if 'layer id key' in provider_dict:
provider_kwargs['layer_id_key'] = provider_dict['layer id key']
- elif str(_class) == 'TileStache.Sandwich.Provider':
- provider_kwargs['stack'] = provider_dict['stack']
+ elif hasattr(_class, 'prepareKeywordArgs'):
+ provider_kwargs.update(_class.prepareKeywordArgs(provider_dict))
elif 'class' in provider_dict:
_class = loadClassPath(provider_dict['class'])
View
@@ -90,19 +90,22 @@
import Vector
import MBTiles
import Geography
-from .Mapnik import ImageProvider as MapnikImage, GridProvider as MapnikGrid
# Already deprecated; provided for temporary backward-compatibility with
# old location of Mapnik provider. TODO: remove in next major version.
-Mapnik = MapnikImage
+try:
+ from .Mapnik import ImageProvider as Mapnik
+except ImportError:
+ pass
def getProviderByName(name):
""" Retrieve a provider object by name.
Raise an exception if the name doesn't work out.
"""
if name.lower() == 'mapnik':
- return MapnikImage
+ from .Mapnik import ImageProvider
+ return ImageProvider
elif name.lower() == 'proxy':
return Proxy
@@ -117,7 +120,8 @@ def getProviderByName(name):
return MBTiles.Provider
elif name.lower() == 'mapnik grid':
- return MapnikGrid
+ from .Mapnik import GridProvider
+ return GridProvider
elif name.lower() == 'sandwich':
import Sandwich
@@ -164,6 +168,20 @@ def __init__(self, layer, url=None, provider_name=None):
else:
raise Exception('Missing required url or provider parameter to Proxy provider')
+ @staticmethod
+ def prepareKeywordArgs(config_dict):
+ '''
+ '''
+ kwargs = dict()
+
+ if 'url' in config_dict:
+ kwargs['url'] = config_dict['url']
+
+ if 'provider' in config_dict:
+ kwargs['provider_name'] = config_dict['provider']
+
+ return kwargs
+
def renderTile(self, width, height, srs, coord):
"""
"""
@@ -222,6 +240,17 @@ def __init__(self, layer, template, referer=None):
self.template = Template(template)
self.referer = referer
+ @staticmethod
+ def prepareKeywordArgs(config_dict):
+ '''
+ '''
+ kwargs = {'template': config_dict['template']}
+
+ if 'referer' in config_dict:
+ kwargs['referer'] = config_dict['referer']
+
+ return kwargs
+
def renderArea(self, width, height, srs, xmin, ymin, xmax, ymax, zoom):
""" Return an image for an area.
View
@@ -143,6 +143,12 @@ def __init__(self, layer, stack):
self.config = layer.config
self.stack = stack
+ @staticmethod
+ def prepareKeywordArgs(config_dict):
+ '''
+ '''
+ return {'stack': config_dict['stack']}
+
def renderTile(self, width, height, srs, coord):
rendered = draw_stack(self.stack, coord, self.config, dict())

0 comments on commit c4e9d57

Please sign in to comment.