Skip to content

Commit

Permalink
Merge f9eebff into cd3776d
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Oct 31, 2013
2 parents cd3776d + f9eebff commit e9eaf17
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 12 deletions.
40 changes: 30 additions & 10 deletions tilecloud_chain/__init__.py
Expand Up @@ -119,6 +119,8 @@ class TileGeneration:
geom = None

def __init__(self, config_file, options=None, layer_name=None):
self.close_actions = []

if options is not None:
if not hasattr(options, 'bbox'):
options.bbox = None
Expand Down Expand Up @@ -596,13 +598,23 @@ def get_store(self, cache, layer, dimensions=None, read_only=False):
) + '.bsddb'
if not os.path.exists(os.path.dirname(filename)):
os.makedirs(os.path.dirname(filename))
db = bsddb.hashopen(
filename,
# and os.path.exists(filename) to avoid error on non existing file
'r' if read_only and os.path.exists(filename) else 'c'
)

class Close:
def __call__(self):
print 'close'
self.db.close()

ca = Close()
ca.db = db
self.close_actions.append(ca)

cache_tilestore = BSDDBTileStore(
bsddb.hashopen(
filename,
# and os.path.exists(filename) to avoid error on non existing file
'r' if read_only and os.path.exists(filename) else 'c'
),
content_type=layer['mime_type'],
db, content_type=layer['mime_type'],
)
elif cache['type'] == 'filesystem':
# on filesystem
Expand Down Expand Up @@ -1227,11 +1239,19 @@ class DropEmpty:
Create a filter for dropping all tiles with errors.
"""

def __init__(self, gene):
self.gene = gene

def __call__(self, tile):
if not tile or not tile.data: # pragma: no cover
logger.error("The tile: %(tilecoord)s is empty")
if 'error_file' in self.config['generation']:
self.log_tiles_error(tilecoord=tile.tilecoord, error='The tile is empty')
#print 9999
#print tile.tilecoord if tile else 'not defined'
if not tile or not tile.data:
#print 7777
logger.error("The tile: %(tilecoord)s is empty" % {
'tilecoord': tile.tilecoord if tile else 'not defined'
})
if 'error_file' in self.gene.config['generation'] and tile:
self.gene.log_tiles_error(tilecoord=tile.tilecoord, error='The tile is empty')
return None
else:
return tile
Expand Down
5 changes: 4 additions & 1 deletion tilecloud_chain/generate.py
Expand Up @@ -255,7 +255,7 @@ def add_elapsed_togenerate(metatile):

if options.role in ('local', 'slave'):
gene.add_error_filters(logger)
gene.ifilter(DropEmpty())
gene.ifilter(DropEmpty(gene))
gene.imap(self.inc_tiles_size)

if options.time:
Expand Down Expand Up @@ -335,6 +335,9 @@ def __call__(self, tile):
self.tiles_size / self.nb_tiles_stored if self.nb_tiles_stored != 0 else -1
)

for ca in gene.close_actions:
ca()

if cache_tilestore is not None and hasattr(cache_tilestore, 'connection'):
cache_tilestore.connection.close()

Expand Down
3 changes: 2 additions & 1 deletion tilecloud_chain/tests/test_serve.py
Expand Up @@ -731,7 +731,7 @@ def test_mbtiles_rest(self, l):
)
# use delete to don't delete the repository
self.assert_tiles_generated_deleted(
cmd='./buildout/bin/generate_controller --capabilities -c tilegeneration/test-serve.yaml',
cmd='./buildout/bin/generate_controller -d --capabilities -c tilegeneration/test-serve.yaml',
main_func=controller.main,
directory="/tmp/tiles/mbtiles/",
tiles_pattern='1.0.0/%s',
Expand Down Expand Up @@ -825,6 +825,7 @@ def test_bsddb_rest(self, l):
Time per tiles: [0-9]+ ms
Size per tile: 4[0-9][0-9] o
close
""",
)
# use delete to don't delete the repository
Expand Down

0 comments on commit e9eaf17

Please sign in to comment.