Commit 4aa101fe authored by Vuillaume's avatar Vuillaume
Browse files

allow kwargs to be passed to ZipUrl through get_codemeta functions

parent 206a99b8
......@@ -677,11 +677,14 @@ class Record:
record = get_record(record_id=record_id, sandbox=sandbox)
return record
def get_codemeta(self):
def get_codemeta(self, **zipurl_kwargs):
"""
Get codemeta metadata from the record (can also be in a zip archive).
Raises an error if no `codemeta.json` file is found.
:param zipurl_kwargs: dict
kwargs for `eossr.utils.ZipUrl`
:return: dict
codemeta metadata
"""
......@@ -698,7 +701,7 @@ class Record:
elif len(ziparchives) > 0:
for zipurl in ziparchives:
try:
return get_codemeta_from_zipurl(zipurl)
return get_codemeta_from_zipurl(zipurl, **zipurl_kwargs)
except FileNotFoundError:
pass
raise FileNotFoundError(f"No `codemeta.json` file found in record {self.id}")
......
......@@ -34,7 +34,7 @@ def test_ZipUrl_buffer_success():
def test_get_codemeta_from_zipurl():
codemeta = eutils.get_codemeta_from_zipurl(_testurl)
codemeta = eutils.get_codemeta_from_zipurl(_testurl, timeout=10, initial_buffer_size=100)
assert codemeta['name'] == 'eossr'
......
......@@ -25,7 +25,9 @@ class ZipUrl(remotezip.RemoteZip, ZipFile):
try:
super().__init__(url, initial_buffer_size=initial_buffer_size, **kwargs)
except requests.packages.urllib3.exceptions.ProtocolError as e:
raise urllib3.exceptions.ProtocolError(f"{str(e)}\nTry lowering the initial buffer size for this zipfile")
raise urllib3.exceptions.ProtocolError(
f"{str(e)}\nTry lowering the initial buffer size for this zipfile"
) from e
def find_files(self, filename):
"""
......@@ -50,7 +52,7 @@ class ZipUrl(remotezip.RemoteZip, ZipFile):
return codemeta
def get_codemeta_from_zipurl(url):
def get_codemeta_from_zipurl(url, **zipurl_kwargs):
"""
Extract and reads codemeta metadata from a zip url.
A codemeta.json file must be present in the zip archive.
......@@ -60,7 +62,8 @@ def get_codemeta_from_zipurl(url):
:return: dictionnary
metadata in the codemeta.json file in the zip archive
"""
zipurl = ZipUrl(url, initial_buffer_size=100)
zipurl_kwargs.setdefault('initial_buffer_size', 100)
zipurl = ZipUrl(url, **zipurl_kwargs)
return zipurl.get_codemeta()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment