@@ -377,23 +377,47 @@ def parse(cls, location, package_only=True):
377
377
378
378
# TODO: Create function that determines package type from download URL,
379
379
# 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
+
399
+ extra_data = {}
400
+ if 'vcs_commit_hash' in metadata_fields :
401
+ extra_data ['vcs_commit_hash' ] = metadata_fields ['vcs_commit_hash' ]
402
+ if 'upstream_hash' in metadata_fields :
403
+ extra_data ['upstream_hash' ] = metadata_fields ['upstream_hash' ]
404
+
380
405
package_data = dict (
381
406
datasource_id = cls .datasource_id ,
382
- type = metadata_fields . get ( 'upstream_type' , metadata_fields . get ( ' package_type' , cls . default_package_type )) ,
407
+ type = package_type ,
383
408
name = metadata_fields .get ('name' ),
384
409
version = metadata_fields .get ('version' ),
385
- extracted_license_statement = metadata_fields . get ( 'licenses' , metadata_fields . get ( 'license_expression' )) ,
410
+ extracted_license_statement = extracted_license_statement ,
386
411
parties = parties ,
387
- homepage_url = metadata_fields . get ( 'upstream_address' , metadata_fields . get ( ' homepage_url' )) ,
412
+ homepage_url = homepage_url ,
388
413
download_url = metadata_fields .get ('download_url' ),
389
414
vcs_url = metadata_fields .get ('vcs_url' ),
390
415
sha1 = metadata_fields .get ('download_archive_sha1' ),
391
- # TODO: Store 'upstream_hash` somewhere
416
+ extra_data = extra_data
392
417
)
393
- if 'vcs_commit_hash' in metadata_fields :
394
- package_data ["extra_data" ] = dict (vcs_commit_hash = metadata_fields ['vcs_commit_hash' ])
395
418
if 'package_url' in metadata_fields :
396
419
package_data .update (PackageURL .from_string (metadata_fields ['package_url' ]).to_dict ())
420
+
397
421
yield models .PackageData .from_data (package_data , package_only = True )
398
422
399
423
0 commit comments