33import json
44from licensedcode .cache import get_index
55from licensedcode .models import load_licenses
6- from licensedcode .models import Rule
7- from licensedcode .models import rules_data_dir
86
97
108def find_osi_map (license : "OSI License Object" ):
@@ -13,6 +11,7 @@ def find_osi_map(license: "OSI License Object"):
1311 """
1412 idx = get_index ()
1513 osi_key = license ['id' ]
14+ # search for Scancode License matching OSI Key
1615 matches = list (idx .match (query_string = osi_key ))
1716 if not matches :
1817 return None
@@ -24,22 +23,26 @@ def add_osi_key(obj: "OSI License Object"):
2423 Add OSI License Key derived from OSI License Object `obj`
2524 """
2625 licenses = licensedcode .cache .get_licenses_db ()
27- result = find_osi_map (obj )
28- osi_key = obj ['id' ]
29- if not result :
30- return None
26+ # find matching Scancode License Object for `obj`
27+ result = find_osi_map (obj )
28+ # derive OSI License Key from `obj`
29+ osi_key = obj ['id' ]
30+ if not result : # no matching Scancode License found
31+ return None
3132 mapped_license = licenses [result ] # license object from Scancode
32- print (mapped_license .key )
33- licenses_path = "src/licensedcode/data/licenses/"
33+ licenses_path = "src/licensedcode/data/licenses/" # licenses directory
3434 file_to_modify = open (licenses_path + mapped_license .key + ".yml" , "a" )
3535 file_to_modify .write ("osi_license_key: " + osi_key )
3636
37+
3738def add_osi_keys ():
3839 """
39- For every possible OSI License, match and add OSI Key to exiting Scancode License
40+ For every possible OSI License, match and add OSI Key to existing Scancode License
4041 """
42+ #retrieve OSI License Objects
4143 contents = urllib .request .urlopen ("https://api.opensource.org/licenses/" ).read ().decode ()
4244 data = json .loads (contents )
45+ # for each OSI License Object, update matching Scancode License Object
4346 for obj in data :
4447 add_osi_key (obj )
4548
0 commit comments