Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MNT: Extract all NE resources from the zip file #2477

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading