[Tilecache] [rindahl@lrcwe.com: Tilecache patch - Corrected]

Christopher Schmidt crschmidt at metacarta.com
Sun Jan 18 21:20:12 EST 2009


Bruce,

I'm forwarding this to the list, because I couldn't find it earlier,
going through my patches. Looking through the code, I feel like perhaps
this one needs to be a bit more baked before I toss it into SVN. For
now, I think I'm going to leave it out of 2.10, and just work on it
after the release.

-- Chris

----- Forwarded message from Bruce Rindahl <rindahl at lrcwe.com> -----

From: Bruce Rindahl <rindahl at lrcwe.com>
To: Christopher Schmidt <crschmidt at metacarta.com>
Date: Tue, 16 Dec 2008 13:04:52 -0700
Subject: Tilecache patch - Corrected
Reply-To: rindahl at lrcwe.com

Christopher
Sorry - I hadn't fully tested the patch and merged all my changes into 
the SVN branch.

I don't think I will use the use_tms_paths option with my S3 buckets. As 
you know S3 is really strange storage.  If you create directories with 
the use_tms_paths option some programs can see the directories (S3 
Firefox extension) while other programs (s3fs in linux) cannot.  Unless 
I hear one way is faster I think I will stay.  My patch works either way.

My patch also has an additional commented out line that adds the tile 
extension to the tile.  It would be nice to know if the tile is stored 
as a JPEG or PNG but I don't know if it is worth the effort of renamimg 
100K files.

Finally I will be looking into modifying tilecahe to use S3 storage as 
read only.  This way I can publish a semi-public bucket that other 
Tilecache progams can access without my keys.

Thanks again
Bruce Rindahl

//
//


Only in trunk\tilecache: .svn
Only in trunk\tilecache: docs
Only in trunk\tilecache: tests
Only in \projects\web\tilecache\TileCache: __init__.pyc
Only in \projects\web\tilecache\TileCache: Cache.pyc
Only in \projects\web\tilecache\TileCache\Caches: __init__.pyc
diff -r -u trunk\tilecache\TileCache\Caches\AWSS3.py \projects\web\tilecache\TileCache\Caches\AWSS3.py
--- trunk\tilecache\TileCache\Caches\AWSS3.py	Tue Dec 16 10:22:16 2008
+++ \projects\web\tilecache\TileCache\Caches\AWSS3.py	Tue Dec 16 12:47:00 2008
@@ -28,7 +28,7 @@
         self.use_tms_paths = use_tms_paths
         if self.module == "amazon":
             self.cache = self.s3.AWSAuthConnection(access_key, secret_access_key)
-            self.cache.create_bucket(self.bucket_name)
+            #self.cache.create_bucket(self.bucket_name)
         else:
             self.cache = self.s3.connection.S3Connection(access_key, secret_access_key)
             self.bucket = self.cache.create_bucket(self.bucket_name)
@@ -39,7 +39,7 @@
         return boto_key
     
     def getKey(self, tile):
-        if self.use_tms_paths == True or self.use_tms_paths = "flipped":
+        if self.use_tms_paths == True or self.use_tms_paths == "flipped":
             grid = tile.layer.grid(tile.z) 
             y = tile.y
             if self.use_tms_paths == "flipped":
@@ -49,17 +49,24 @@
             path = ".".join(map(str, [path, tile.layer.extension]))
         else: 
            path = "-".join(map(str, [tile.layer.name, tile.z , tile.x, tile.y]))
+           #path = ".".join(map(str, [path, tile.layer.extension]))
         return path
 
     def get(self, tile):
         key = self.getKey(tile)
-        tile.data = self.getObject(key)
+        #tile.data = self.getObject(key)
+        if tile.layer.bucket != "":
+            tile.data = self.getObject(tile.layer.bucket, key)
+        else:
+            tile.data = self.getObject(self.bucket_name, key)
         return tile.data
     
-    def getObject(self, key):
+    #def getObject(self, key):
+    def getObject(self, bucket, key):
         data = None
         if self.module == "amazon":
-            response = self.cache.get(self.bucket_name, key)
+            #response = self.cache.get(self.bucket_name, key)
+            response = self.cache.get(bucket, key)
             if not response.object.data.startswith("<?xml"):
                 data = response.object.data
         else:
@@ -73,23 +80,35 @@
     def set(self, tile, data):
         if self.readonly: return data
         key = self.getKey(tile)
-        self.setObject(key, data)
+        #self.setObject(key, data)
+        if tile.layer.bucket != "":
+            self.setObject(tile.layer.bucket, key, data)
+        else:
+            self.setObject(self.bucket_name, key, data)
         return data
     
-    def setObject(self, key, data):
+    #def setObject(self, key, data):
+    def setObject(self, bucket, key, data):
         if self.module == "amazon":
-            self.cache.put(self.bucket_name, key, self.s3.S3Object(data))
+            #self.cache.put(self.bucket_name, key, self.s3.S3Object(data))
+            self.cache.put(bucket, key, self.s3.S3Object(data))
         else:
             self.getBotoKey(key).set_contents_from_string(data)
             self.bucket.connection.connection.close()    
     
     def delete(self, tile):
         key = self.getKey(tile)
-        self.deleteObject(key) 
+        #self.deleteObject(key) 
+        if tile.layer.bucket != "":
+            self.deleteObject(tile.layer.bucket,key) 
+        else:
+            self.deleteObject(self.bucket_name, key) 
     
-    def deleteObject(self, key):
+    #def deleteObject(self, key):
+    def deleteObject(self, bucket, key):
         if self.module == "amazon":
-            self.cache.delete(self.bucket_name, key)
+            #self.cache.delete(self.bucket_name, key)
+            self.cache.delete(bucket, key)
         else: 
             self.getBotoKey(key).delete()
             
Only in \projects\web\tilecache\TileCache\Caches: AWSS3.pyc
Only in \projects\web\tilecache\TileCache\Caches: S3.pyc
Only in \projects\web\tilecache\TileCache: Client.pyc
diff -r -u trunk\tilecache\TileCache\Layer.py \projects\web\tilecache\TileCache\Layer.py
--- trunk\tilecache\TileCache\Layer.py	Tue Dec 16 10:22:16 2008
+++ \projects\web\tilecache\TileCache\Layer.py	Tue Dec 16 12:41:06 2008
@@ -99,7 +99,7 @@
                   "cache", "debug", "description", 
                   "watermarkimage", "watermarkopacity",
                   "extent_type", "tms_type", "units", "mime_type",
-                  "spherical_mercator", "metadata")
+                  "spherical_mercator", "metadata", "bucket")
     
     config_properties = [
       {'name':'spherical_mercator', 'description':'Layer is in spherical mercator. (Overrides bbox, maxresolution, SRS, Units)', 'type': 'boolean'},
@@ -108,6 +108,7 @@
       {'name':'bbox', 'description':'Bounding box of the layer grid', 'default':'-180,-90,180,90'},
       {'name':'srs', 'description':'Spatial Reference System for the layer', 'default':'EPSG:4326'},
       {'name':'data_extent', 'description':'Bounding box of the layer data. (Same SRS as the layer grid.)', 'default':"", 'type': 'map'},
+      {'name':'bucket', 'description':'AWS S3 bucket name', 'default':''},
     ]  
     
     def __init__ (self, name, layers = None, bbox = (-180, -90, 180, 90),
@@ -117,7 +118,7 @@
                         extension = "png", mime_type = None, cache = None,  debug = True, 
                         watermarkimage = None, watermarkopacity = 0.2,
                         spherical_mercator = False,
-                        extent_type = "strict", units = "degrees", tms_type = "", **kwargs ):
+                        extent_type = "strict", units = "degrees", tms_type = "", bucket = "", **kwargs ):
         """Take in parameters, usually from a config file, and create a Layer.
 
         >>> l = Layer("Name", bbox="-12,17,22,36", debug="no")
@@ -134,6 +135,7 @@
         self.name   = name
         self.description = description
         self.layers = layers or name
+        self.bucket = bucket
         self.paletted = False
         
         self.spherical_mercator = spherical_mercator and spherical_mercator.lower() in ["yes", "y", "t", "true"]
Only in \projects\web\tilecache\TileCache: Layer.pyc
Only in \projects\web\tilecache\TileCache\Layers: __init__.pyc
Only in \projects\web\tilecache\TileCache\Layers: WMS.pyc
Only in \projects\web\tilecache\TileCache: Service.pyc
Only in \projects\web\tilecache\TileCache\Services: __init__.pyc
Only in \projects\web\tilecache\TileCache\Services: WMS.pyc
Only in trunk\tilecache: tilecache.cfg


----- End forwarded message -----

-- 
Christopher Schmidt
MetaCarta



More information about the Tilecache mailing list