Exemplo n.º 1
0
 def get_one(self, tile):
     filename = self.tilelayout.filename(tile.tilecoord)
     if os.path.isfile(filename):
         return self._get_one(tile, filename)
     else:
         if tile.content_type:
             tileformat = TileFormat.from_content_type(tile.content_type)
         elif self.content_type:
             tileformat = TileFormat.from_content_type(self.content_type)
         else:
             tileformat = TileFormat()
         filename = filename + tileformat.ext
         if os.path.isfile(filename):
             tile.content_type = tileformat.content_type
             return self._get_one(tile, filename)
         else:
             # filenames = map(lambda ext: filename + ext, tileformat.extentions)
             # for filename in filenames:
             for ext in tileformat.extentions:
                 filename2 = filename + ext
                 if os.path.isfile(filename2):
                     tileformat = TileFormat.from_extention(ext)
                     tile.content_type = tileformat.content_type
                     tile = self._get_one(tile, filename2)
                     if tile is not None:
                         return tile
             return None
Exemplo n.º 2
0
 def put_one(self, tile):
     assert tile.data is not None
     filename = self.tilelayout.filename(tile.tilecoord)
     if tile.content_type:
         tileformat = TileFormat.from_content_type(tile.content_type)
     elif self.content_type:
         tileformat = TileFormat.from_content_type(self.content_type)
     else:
         tileformat = TileFormat()
     filename = filename + tileformat.ext
     dirname = os.path.dirname(filename)
     if not os.path.exists(dirname):
         os.makedirs(dirname)
     with open(filename, 'wb') as file:
         file.write(tile.data)
     return tile
Exemplo n.º 3
0
 def put_one(self, tile):
     content_type = getattr(tile, 'content_type', None)
     tileformat = TileFormat.from_content_type(content_type)
     self.tiles[tile.tilecoord] = [
         tileformat.typeindex,
         getattr(tile, 'data', None)
     ]
     return tile
Exemplo n.º 4
0
 def put_one(self, tile):
     assert tile.data is not None
     if tile.content_type:
         tileformat = TileFormat.from_content_type(tile.content_type)
     elif self.content_type:
         tileformat = TileFormat.from_content_type(self.content_type)
     else:
         tileformat = TileFormat()
     mongo_tile = {
             "zoom_level":tile.tilecoord.z,
             "tile_column":tile.tilecoord.x,
             "tile_row":tile.tilecoord.y,
             "tile_format":tileformat.typeindex,
             "tile_data":tile.data
             }
     tile_id = self.collection.insert(mongo_tile)
     return tile
Exemplo n.º 5
0
 def get_one(self, tile):
     try:
         typeindex, tile.data = self.tiles[tile.tilecoord]
         tileformat = TileFormat.from_type_index(typeindex)
         tile.content_type = tileformat.content_type
     except KeyError:
         return None
     return tile
Exemplo n.º 6
0
 def get_one(self, tile):
     try:
         typeindex, tile.data = self.tiles[tile.tilecoord]
         tileformat = TileFormat.from_type_index(typeindex)
         tile.content_type = tileformat.content_type
     except KeyError:
         return None
     return tile
Exemplo n.º 7
0
 def get_one(self, tile):
     mongo_tilecoord = {
             "zoom_level":tile.tilecoord.z,
             "tile_column":tile.tilecoord.x,
             "tile_row":tile.tilecoord.y
             }
     mongo_tile = self.collection.find_one(mongo_tilecoord)
     if mongo_tile is None:
         return None
     tile.data = mongo_tile["tile_data"]
     tileformat = TileFormat.from_type_index(mongo_tile["tile_format"])
     tile.content_type = tileformat.content_type
     return tile
Exemplo n.º 8
0
 def get_all(self):
     for tilecoord, typeindex, data in self.tiles.iteritems():
         tile = Tile(tilecoord, data=data)
         tileformat = TileFormat.from_type_index(typeindex)
         tile.content_type = tileformat.content_type
         yield tile
Exemplo n.º 9
0
 def put_one(self, tile):
     content_type = getattr(tile, 'content_type', None)
     tileformat = TileFormat.from_content_type(content_type)
     self.tiles[tile.tilecoord] = [tileformat.typeindex, getattr(tile, 'data', None)]
     return tile
Exemplo n.º 10
0
 def get_all(self):
     for tilecoord, typeindex, data in self.tiles.iteritems():
         tile = Tile(tilecoord, data=data)
         tileformat = TileFormat.from_type_index(typeindex)
         tile.content_type = tileformat.content_type
         yield tile