Skip to content

Commit

Permalink
Fix coverage and simplify the code
Browse files Browse the repository at this point in the history
  • Loading branch information
adrien-berchet committed Oct 19, 2020
1 parent 8237887 commit a7b4128
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions lib/cartopy/io/img_tiles.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import io
import json
import os
from uuid import uuid4
import warnings

from PIL import Image
Expand Down Expand Up @@ -52,12 +53,7 @@ def __init__(self, desired_tile_form='RGB',
# a change of user_agent may fix the issue.
self.cache_path = cache_path
self.cache = {}
if self.cache_path is not None:
try:
os.makedirs(self.cache_path)
except OSError:
pass
self._load_cache()
self._load_cache()

def image_for_domain(self, target_domain, target_z):
tiles = []
Expand Down Expand Up @@ -88,8 +84,7 @@ def fetch_tile(tile):

img, extent, origin = _merge_tiles(tiles)

if self.cache_path is not None:
self._save_cache()
self._save_cache()

return img, extent, origin

Expand All @@ -107,7 +102,8 @@ def _fetch_cache(self, files):
def _save_cache(self):
"""Save the cache"""
if self.cache_path is not None and self.cache:
from uuid import uuid4
if not os.path.exists(self.cache_path):
os.makedirs(self.cache_path)
files = self._cache_files()
already_cached = self._fetch_cache(files)

Expand Down

0 comments on commit a7b4128

Please sign in to comment.