Skip to content

Commit

Permalink
Merge b9563fa into 5ed51cd
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Apr 10, 2014
2 parents 5ed51cd + b9563fa commit 0a67171
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 7 deletions.
3 changes: 2 additions & 1 deletion README.rst
Expand Up @@ -320,7 +320,8 @@ Process
-------

We can configure some tile commands to process the tiles.
They can be automatically be called in the tile generation it we set the property ``post_process`` in the layer configuration.
They can be automatically be called in the tile generation it we set the property
``post_process`` or ``pre_hash_post_process`` in the layer configuration.

The process is a set of names processes, and each one has a list of commands declared like this:

Expand Down
14 changes: 9 additions & 5 deletions tilecloud_chain/__init__.py
Expand Up @@ -354,6 +354,9 @@ def __init__(self, config_file, options=None, layer_name=None):
regex="^[a-zA-Z0-9_]+$"
) or error

error = self.validate(
layer, name, 'pre_hash_post_process', attribute_type=str, default=False
) or error
error = self.validate(
layer, name, 'post_process', attribute_type=str, default=False
) or error
Expand Down Expand Up @@ -1453,7 +1456,7 @@ def __init__(self, config, options):

def __call__(self, tile):
if tile and tile.data:
name_in = tempfile.mkstemp()[1]
fd_in, name_in = tempfile.mkstemp()
file_in = open(name_in, 'wb')
file_in.write(tile.data)
file_in.close()
Expand All @@ -1473,7 +1476,7 @@ def __call__(self, tile):
args.append(cmd['arg']['quiet'])

if cmd['need_out']:
name_out = tempfile.mkstemp()[1]
fd_out, name_out = tempfile.mkstemp()
os.unlink(name_out)
else: # pragma: no cover
name_out = name_in
Expand All @@ -1496,13 +1499,14 @@ def __call__(self, tile):
return tile

if cmd['need_out']:
os.unlink(name_in)
os.close(fd_in)
name_in = name_out
fd_in = fd_out

file_out = open(name_out, 'rb')
file_out = open(name_in, 'rb')
tile.data = file_out.read()
file_out.close()
os.unlink(name_out)
os.close(fd_in)

return tile

Expand Down
6 changes: 5 additions & 1 deletion tilecloud_chain/generate.py
Expand Up @@ -187,7 +187,9 @@ def add_elapsed_togenerate(metatile):
gene.imap(Logger(logger, logging.INFO, '%(tilecoord)s'))

self.count_tiles = gene.counter()
gene.process()

if 'pre_hash_post_process' in gene.layer:
gene.process(gene.layer['pre_hash_post_process'])

if options.role == 'hash':
gene.imap(HashLogger('empty_tile_detection'))
Expand All @@ -205,6 +207,8 @@ def add_elapsed_togenerate(metatile):
count=count_tiles_dropped,
))

gene.process()

if options.role in ('local', 'slave'):
gene.add_error_filters()
gene.ifilter(DropEmpty(gene))
Expand Down
11 changes: 11 additions & 0 deletions tilecloud_chain/tests/test_controller.py
Expand Up @@ -1453,6 +1453,7 @@ def test_apache_s3(self):
name: all
params: {}
post_process: false
pre_hash_post_process: false
px_buffer: false
type: wms
url: http://localhost/mapserv
Expand All @@ -1478,6 +1479,7 @@ def test_apache_s3(self):
name: line
params: {PARAM: value}
post_process: false
pre_hash_post_process: false
px_buffer: false
type: wms
url: http://localhost/mapserv
Expand All @@ -1500,6 +1502,7 @@ def test_apache_s3(self):
name: mapnik
output_format: png
post_process: false
pre_hash_post_process: false
px_buffer: false
type: mapnik
wmts_style: default
Expand All @@ -1526,6 +1529,7 @@ def test_apache_s3(self):
name: mapnik_grid
output_format: grid
post_process: false
pre_hash_post_process: false
px_buffer: false
resolution: 16
type: mapnik
Expand All @@ -1551,6 +1555,7 @@ def test_apache_s3(self):
name: mapnik_grid_drop
output_format: grid
post_process: false
pre_hash_post_process: false
px_buffer: false
resolution: 16
type: mapnik
Expand All @@ -1575,6 +1580,7 @@ def test_apache_s3(self):
name: point
params: {}
post_process: false
pre_hash_post_process: false
px_buffer: false
sqs: {queue: sqs_point, region: eu-west-1}
type: wms
Expand All @@ -1599,6 +1605,7 @@ def test_apache_s3(self):
name: point_hash_no_meta
params: {}
post_process: false
pre_hash_post_process: false
px_buffer: false
type: wms
url: http://localhost/mapserv
Expand All @@ -1625,6 +1632,7 @@ def test_apache_s3(self):
name: point_hash
params: {}
post_process: false
pre_hash_post_process: false
px_buffer: false
type: wms
url: http://localhost/mapserv
Expand All @@ -1650,6 +1658,7 @@ def test_apache_s3(self):
name: point_px_buffer
params: {}
post_process: false
pre_hash_post_process: false
px_buffer: 100.0
type: wms
url: http://localhost/mapserv
Expand All @@ -1675,6 +1684,7 @@ def test_apache_s3(self):
name: polygon
params: {}
post_process: false
pre_hash_post_process: false
px_buffer: false
type: wms
url: http://localhost/mapserv
Expand All @@ -1700,6 +1710,7 @@ def test_apache_s3(self):
name: polygon2
params: {}
post_process: false
pre_hash_post_process: false
px_buffer: false
type: wms
url: http://localhost/mapserv
Expand Down

0 comments on commit 0a67171

Please sign in to comment.