Skip to content

Instantly share code, notes, and snippets.

@PatteSI
Created March 1, 2022 15:02
Show Gist options
  • Save PatteSI/5904f4bdfb149dc1ce8c73da53e2f6ae to your computer and use it in GitHub Desktop.
Save PatteSI/5904f4bdfb149dc1ce8c73da53e2f6ae to your computer and use it in GitHub Desktop.
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