Commit df660eaf authored by Boris Baldassari's avatar Boris Baldassari
Browse files

Add maven coordinates to clearlydefined curation script.

parent 47e8dcb6
......@@ -17,6 +17,7 @@ import requests
import getopt
import sys
import yaml
import numpy as np
from datetime import datetime
from os.path import isfile
......@@ -52,6 +53,8 @@ with open(file_in, 'r') as f:
exit()
packages = doc['evaluator']['violations']
packages_np = np.array(packages)
packages = np.unique(packages_np)
licenses = {}
urls={}
......@@ -61,24 +64,31 @@ for package in packages:
print(f"- Working on '{pkg}'..", end=" ")
# Transform coordinates
parts = pkg.split(':')
url = 'https://api.clearlydefined.io/definitions/'
if pkg.startswith('NPM:'):
coordinates = f"npm/npmjs/-/{parts[-2]}/{parts[-1]}"
url = 'https://api.clearlydefined.io/definitions/' + coordinates
# Do a get request to clearlydefined, as described in
# https://docs.clearlydefined.io/using-data
r = requests.get(url)
if r.status_code == 200:
answer = r.json()
if 'licensed' in answer and 'declared' in answer['licensed']:
print(f"Found license: {answer['licensed']['declared']}")
licenses[pkg] = answer['licensed']['declared']
urls[pkg] = 'https://clearlydefined.io/definitions/' + coordinates
else:
print("No declared license found on clearlydefined.")
else:
print("Not found on clearlydefined (status_code).")
url += coordinates
elif pkg.startswith('Maven:'):
namespace = parts[-3] if (parts[-3] != '') else '-'
coordinates = f"maven/mavencentral/{namespace}/{parts[-2]}/{parts[-1]}"
url += coordinates
else:
print("Package type not recognised.")
continue
# Do a get request to clearlydefined, as described in
# https://docs.clearlydefined.io/using-data
r = requests.get(url)
if r.status_code == 200:
answer = r.json()
if 'licensed' in answer and 'declared' in answer['licensed']:
print(f"Found license: {answer['licensed']['declared']}")
licenses[pkg] = answer['licensed']['declared']
urls[pkg] = 'https://clearlydefined.io/definitions/' + coordinates
else:
print("No declared license found on clearlydefined.")
else:
print("Not found on clearlydefined (status_code).")
print(f"\nFound {len(licenses)} curations.")
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment