Forked from PatteSI/gist:5904f4bdfb149dc1ce8c73da53e2f6ae
Created
March 2, 2022 17:08
-
-
Save pombredanne/773c73330b777400e57d719a8ad9dd09 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json | |
file = 'evaluated-model-things.json' | |
# list all license references here that frequently cause false positives | |
scanRefLicencesList = [ | |
'LicenseRef-scancode-unknown-license-reference', | |
'LicenseRef-scancode-free-unknown', | |
'LicenseRef-scancode-proprietary-license', | |
'LicenseRef-scancode-generic-export-compliance', | |
'LicenseRef-scancode-generic-cla', | |
'LicenseRef-scancode-public-domain', | |
'LicenseRef-scancode-warranty-disclaimer'] | |
licenseIDs = [] | |
falsePosFindings = {} | |
# place the evaluate-model file in the same directory as this python script | |
with open(file) as json_file: | |
data = json.load(json_file) | |
for license in data['licenses']: | |
#print('license: '+license['id']) | |
if license['id'] in scanRefLicencesList: | |
print(str(license['_id'])+' is this license'+license['id']) | |
licenseIDs.append(license['_id']) | |
print (*licenseIDs) | |
for package in data['packages']: | |
if package['is_project']=='true': | |
break | |
try: | |
for finding in package['findings']: | |
try: | |
if finding['license'] in licenseIDs: | |
id = package['id'] | |
url = package['homepage_url'] | |
purl = package['purl'] | |
start = finding['start_line'] | |
end = finding['end_line'] | |
path = finding['path'] | |
#build new dict with all findings | |
falsePosFindings[id] = {} | |
falsePosFindings[id]['homepage_url']= url | |
falsePosFindings[id]['purl']= purl | |
falsePosFindings[id]['path']= path | |
falsePosFindings[id]['start_line']= start | |
falsePosFindings[id]['end_line']= end | |
print(url) | |
except KeyError: | |
continue | |
except KeyError: | |
continue | |
print(falsePosFindings) | |
with open('falsePosFindings.json', 'w') as jsonFile: | |
#jsonOutput = json.dumps(falsePosFindings, indent=4) | |
json.dump(falsePosFindings, jsonFile, indent=4) | |
jsonFile.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment