[Tilecache] dynamic config

Attila Csipa plists at prometheus.org.yu
Tue Feb 12 16:33:38 EST 2008


I needed to do some dynamic config generation for tilecache (add new layers on 
the fly, per user layers, etc), so here is the option to include additional 
config files, or, recursively, whole directories.


Index: tilecache/tilecache.cfg
===================================================================
--- tilecache/tilecache.cfg     (revision 253)
+++ tilecache/tilecache.cfg     (working copy)
@@ -13,6 +13,10 @@
 #[metadata]
 #crossdomain_sites=openstreetmap.org,openaerialmap.org

+# Another metadata option is to include additional files or directories in
+# your config (f.e. per layer or per user config files)
+#includeconf=/etc/tilecache.conf.d,/var/www/userlayers/public.conf
+
 # [cache] section examples: (mandatory!)
 #
 # Disk:
Index: tilecache/TileCache/Service.py
===================================================================
--- tilecache/TileCache/Service.py      (revision 253)
+++ tilecache/TileCache/Service.py      (working copy)
@@ -94,6 +94,17 @@

             cache = cls.loadFromSection(config, "cache", Cache)

+            if metadata.has_key('includeconf'):
+                files = list(files)
+                for path in metadata['includeconf'].split(","):
+                    if os.path.isfile(path):
+                        files.append(path)
+                    elif os.path.isdir(path):
+                        for (root, dir, file) in os.walk(path):
+                            for name in file:
+                                files.append(os.path.join(root, name))
+                config.read(files)
+
             layers = {}
             for section in config.sections():
                 if section in cls.__slots__: continue



More information about the Tilecache mailing list