@@ -377,23 +377,45 @@ def parse(cls, location, package_only=True):
377377
378378 # TODO: Create function that determines package type from download URL,
379379 # then create a package of that package type from the metadata info
380+
381+ if 'upstream_type' in metadata_fields :
382+ package_type = metadata_fields ['upstream_type' ]
383+ elif 'package_type' in metadata_fields :
384+ package_type = metadata_fields ['package_type' ]
385+ else :
386+ package_type = cls .default_package_type
387+
388+ if 'licenses' in metadata_fields :
389+ extracted_license_statement = metadata_fields ['licenses' ]
390+ else :
391+ extracted_license_statement = metadata_fields .get ('license_expression' )
392+
393+ if 'upstream_address' in metadata_fields :
394+ homepage_url = metadata_fields ['upstream_address' ]
395+ else :
396+ homepage_url = metadata_fields .get ('homepage_url' )
397+
398+ extra_data = dict (
399+ vcs_commit_hash = metadata_fields .get ('vcs_commit_hash' ),
400+ upstream_hash = metadata_fields .get ('upstream_hash' )
401+ )
402+
380403 package_data = dict (
381404 datasource_id = cls .datasource_id ,
382- type = metadata_fields . get ( 'upstream_type' , metadata_fields . get ( ' package_type' , cls . default_package_type )) ,
405+ type = package_type ,
383406 name = metadata_fields .get ('name' ),
384407 version = metadata_fields .get ('version' ),
385- extracted_license_statement = metadata_fields . get ( 'licenses' , metadata_fields . get ( 'license_expression' )) ,
408+ extracted_license_statement = extracted_license_statement ,
386409 parties = parties ,
387- homepage_url = metadata_fields . get ( 'upstream_address' , metadata_fields . get ( ' homepage_url' )) ,
410+ homepage_url = homepage_url ,
388411 download_url = metadata_fields .get ('download_url' ),
389412 vcs_url = metadata_fields .get ('vcs_url' ),
390413 sha1 = metadata_fields .get ('download_archive_sha1' ),
391- # TODO: Store 'upstream_hash` somewhere
414+ extra_data = extra_data
392415 )
393- if 'vcs_commit_hash' in metadata_fields :
394- package_data ["extra_data" ] = dict (vcs_commit_hash = metadata_fields ['vcs_commit_hash' ])
395416 if 'package_url' in metadata_fields :
396417 package_data .update (PackageURL .from_string (metadata_fields ['package_url' ]).to_dict ())
418+
397419 yield models .PackageData .from_data (package_data , package_only = True )
398420
399421
0 commit comments