@@ -114,9 +114,12 @@ def _download_file(
114114 file .write (data )
115115 progress_bar .close ()
116116
117- # TODO: could be a problem of github raw / openflaas
117+ # TODO: keep check or remove?
118118 if total_size_in_bytes != 0 and progress_bar .n != total_size_in_bytes :
119- raise IOError ("Downloaded size does not match Content-Length header" )
119+ localsize = os .path .getsize (filename )
120+ print (f"\n Headers: { response .headers } " )
121+ print (f"\n [WARNING]: Downloaded size { progress_bar .n } does not match Content-Length header { total_size_in_bytes } ( local file size: { localsize } )" )
122+ # raise IOError("Downloaded size does not match Content-Length header")
120123
121124
122125def _download_files (
@@ -407,12 +410,20 @@ def _get_databus_versions_of_artifact(
407410 json_dict = json .loads (json_str )
408411 versions = json_dict .get ("databus:hasVersion" )
409412
410- # Single version case {}
413+ if versions is None :
414+ raise ValueError ("No 'databus:hasVersion' field in artifact JSON-LD" )
415+
411416 if isinstance (versions , dict ):
412417 versions = [versions ]
413- # Multiple versions case [{}, {}]
418+ elif not isinstance (versions , list ):
419+ raise ValueError (
420+ f"Unexpected type for 'databus:hasVersion': { type (versions ).__name__ } "
421+ )
422+
423+ version_urls = [
424+ v ["@id" ] for v in versions if isinstance (v , dict ) and "@id" in v
425+ ]
414426
415- version_urls = [v ["@id" ] for v in versions if "@id" in v ]
416427 if not version_urls :
417428 raise ValueError ("No versions found in artifact JSON-LD" )
418429
@@ -435,13 +446,16 @@ def _get_file_download_urls_from_artifact_jsonld(json_str: str) -> List[str]:
435446 List of all file download URLs in the artifact version.
436447 """
437448
438- databusIdUrl = []
449+ databusIdUrl : List [str ] = []
450+
439451 json_dict = json .loads (json_str )
440452 graph = json_dict .get ("@graph" , [])
441453 for node in graph :
442454 if node .get ("@type" ) == "Part" :
443- id = node .get ("file" )
444- databusIdUrl .append (id )
455+ file_uri = node .get ("file" )
456+ if not isinstance (file_uri , str ):
457+ continue
458+ databusIdUrl .append (file_uri )
445459 return databusIdUrl
446460
447461
@@ -488,10 +502,24 @@ def _get_databus_artifacts_of_group(json_str: str) -> List[str]:
488502 Returns a list of artifact URLs.
489503 """
490504 json_dict = json .loads (json_str )
491- artifacts = json_dict .get ("databus:hasArtifact" , [])
505+ artifacts = json_dict .get ("databus:hasArtifact" )
506+
507+ if artifacts is None :
508+ return []
492509
493- result = []
494- for item in artifacts :
510+ if isinstance (artifacts , dict ):
511+ artifacts_iter = [artifacts ]
512+ elif isinstance (artifacts , list ):
513+ artifacts_iter = artifacts
514+ else :
515+ raise ValueError (
516+ f"Unexpected type for 'databus:hasArtifact': { type (artifacts ).__name__ } "
517+ )
518+
519+ result : List [str ] = []
520+ for item in artifacts_iter :
521+ if not isinstance (item , dict ):
522+ continue
495523 uri = item .get ("@id" )
496524 if not uri :
497525 continue
@@ -538,7 +566,7 @@ def download(
538566 # Auto-detect sparql endpoint from host if not given
539567 if uri_endpoint is None :
540568 uri_endpoint = f"https://{ host } /sparql"
541- print (f"SPARQL endpoint { endpoint } " )
569+ print (f"SPARQL endpoint { uri_endpoint } " )
542570
543571 if group == "collections" and artifact is not None :
544572 print (f"Downloading collection: { databusURI } " )
0 commit comments