Skip to content

Commit

Permalink
MNT: Extract all NE resources from the zip file
Browse files Browse the repository at this point in the history
  • Loading branch information
greglucas committed Nov 13, 2024
1 parent def171d commit b846b3f
Showing 1 changed file with 3 additions and 14 deletions.
17 changes: 3 additions & 14 deletions lib/cartopy/io/shapereader.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import itertools
from pathlib import Path
from urllib.error import HTTPError
from zipfile import ZipFile

import shapefile
import shapely.geometry as sgeom
Expand Down Expand Up @@ -349,25 +350,15 @@ def acquire_resource(self, target_path, format_dict):
:meth:`zip_file_contents` to the target path.
"""
from zipfile import ZipFile

target_dir = Path(target_path).parent
target_dir.mkdir(parents=True, exist_ok=True)

url = self.url(format_dict)

shapefile_online = self._urlopen(url)

zfh = ZipFile(io.BytesIO(shapefile_online.read()), 'r')

for member_path in self.zip_file_contents(format_dict):
member = zfh.getinfo(member_path.replace('\\', '/'))
with open(target_path.with_suffix(
Path(member_path).suffix), 'wb') as fh:
fh.write(zfh.open(member).read())

with ZipFile(io.BytesIO(shapefile_online.read()), 'r') as zfh:
zfh.extractall(target_dir)
shapefile_online.close()
zfh.close()

return target_path

Expand Down Expand Up @@ -456,8 +447,6 @@ def zip_file_contents(self, format_dict):
yield str(p).format(extension=ext, **format_dict)

def acquire_all_resources(self, format_dict):
from zipfile import ZipFile

# Download archive.
url = self.url(format_dict)
try:
Expand Down

0 comments on commit b846b3f

Please sign in to comment.