Skip to content

Commit

Permalink
Merge pull request #35 from makinacorpus/add_ignore_errors
Browse files Browse the repository at this point in the history
Add option to ignore errors during MBTiles creation
  • Loading branch information
leplatrem committed Sep 22, 2014
2 parents 4f538d1 + 594d987 commit fffdd80
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
3 changes: 2 additions & 1 deletion CHANGES
Expand Up @@ -6,6 +6,7 @@ CHANGELOG
==================

* Add delay between tiles downloads retries (by @kiorky)
* Add option to ignore errors during MBTiles creation (e.g. download errors)


2.1.1 (2013-08-27)
Expand Down Expand Up @@ -42,7 +43,7 @@ CHANGELOG

* Rework cache mechanism
* Jpeg tiles support (#14)
* Remove use of temporary files
* Remove use of temporary files
* Image post-processing (#11)

2.0.0-alpha (2012-05-23)
Expand Down
10 changes: 9 additions & 1 deletion landez/tests.py
Expand Up @@ -78,7 +78,7 @@ def test_download_tile(self):
content = mb.tile(tile)
self.assertTrue(content is not None)
# No subdomain keyword
mb = TilesManager(tiles_url="http://tile.cloudmade.com/f1fe9c2761a15118800b210c0eda823c/1/{size}/{z}/{x}/{y}.png")
mb = TilesManager(tiles_url="http://tile.openstreetmap.org/{z}/{x}/{y}.png")
content = mb.tile(tile)
self.assertTrue(content is not None)
# Subdomain in available range
Expand Down Expand Up @@ -133,6 +133,14 @@ def test_run(self):
os.remove('small.mbtiles')
os.remove('big.mbtiles')

def test_run_with_errors(self):
mb = MBTilesBuilder(tiles_url='http://foo.bar')
mb.add_coverage(bbox=(-180.0, -90.0, 180.0, 90.0), zoomlevels=[0, 1])
self.assertRaises(DownloadError, mb.run)
mb = MBTilesBuilder(tiles_url='http://foo.bar', ignore_errors=True)
mb.add_coverage(bbox=(-180.0, -90.0, 180.0, 90.0), zoomlevels=[0, 1])
mb.run()

def test_run_jpeg(self):
output = 'mq.mbtiles'
mb = MBTilesBuilder(filepath=output,
Expand Down
9 changes: 8 additions & 1 deletion landez/tiles.py
Expand Up @@ -233,9 +233,11 @@ def __init__(self, **kwargs):
filepath -- output MBTiles file (default DEFAULT_FILEPATH)
tmp_dir -- temporary folder for gathering tiles (default DEFAULT_TMP_DIR/filepath)
ignore_errors -- ignore errors during MBTiles creation (e.g. download errors)
"""
super(MBTilesBuilder, self).__init__(**kwargs)
self.filepath = kwargs.get('filepath', DEFAULT_FILEPATH)
self.ignore_errors = kwargs.get('ignore_errors', False)
# Gather tiles for mbutil
basename, ext = os.path.splitext(os.path.basename(self.filepath))
self.tmp_dir = kwargs.get('tmp_dir', DEFAULT_TMP_DIR)
Expand Down Expand Up @@ -310,7 +312,12 @@ def run(self, force=False):
# Go through whole list of tiles and gather them in tmp_dir
self.rendered = 0
for (z, x, y) in tileslist:
self._gather((z, x, y))
try:
self._gather((z, x, y))
except Exception as e:
logger.warn(e)
if not self.ignore_errors:
raise

logger.debug(_("%s tiles were missing.") % self.rendered)

Expand Down

0 comments on commit fffdd80

Please sign in to comment.