Skip to content

Commit 1637711

Browse files
authored
Merge pull request #1868 from Gaupeng/develop
Add OSI License Key Mappings
2 parents e1ad0f3 + 817db18 commit 1637711

53 files changed

Lines changed: 105 additions & 1 deletion

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

etc/scripts/osikeys.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import json
2+
import licensedcode.index
3+
import urllib.request
4+
from licensedcode.cache import get_index
5+
from licensedcode.models import load_licenses
6+
7+
8+
def find_osi_map(license: "OSI License Object"):
9+
"""
10+
Return Scancode key mapped to OSI License `license`
11+
"""
12+
idx = get_index()
13+
osi_key = license['id']
14+
# search for Scancode License matching OSI Key
15+
matches = list(idx.match(query_string = osi_key))
16+
if not matches:
17+
return None
18+
return matches[0].rule.license_expression
19+
20+
21+
def add_osi_key(obj: "OSI License Object"):
22+
"""
23+
Add OSI License Key derived from OSI License Object `obj`
24+
"""
25+
licenses = licensedcode.cache.get_licenses_db()
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
32+
mapped_license = licenses[result] # license object from Scancode
33+
licenses_path = "src/licensedcode/data/licenses/" # licenses directory
34+
file_to_modify = open(licenses_path + mapped_license.key + ".yml", "a")
35+
file_to_modify.write("osi_license_key: " + osi_key)
36+
file_to_modify.write("\n")
37+
38+
39+
def add_osi_keys():
40+
"""
41+
For every possible OSI License, match and add OSI Key to existing Scancode License
42+
"""
43+
#retrieve OSI License Objects
44+
contents = urllib.request.urlopen("https://api.opensource.org/licenses/").read().decode()
45+
data = json.loads(contents)
46+
# for each OSI License Object, update matching Scancode License Object
47+
for obj in data:
48+
add_osi_key(obj)
49+
50+
51+
if __name__ == '__main__':
52+
add_osi_keys()

src/licensedcode/data/licenses/adapt-1.0.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ osi_url: http://www.opensource.org/licenses/apl1.0.php
1212
other_urls:
1313
- http://www.opensource.org/licenses/APL-1.0
1414
- https://opensource.org/licenses/APL-1.0
15+
osi_license_key: APL-1.0

src/licensedcode/data/licenses/afl-3.0.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ ignorable_copyrights:
1919
- Copyright (c) 2005 Lawrence Rosen
2020
ignorable_holders:
2121
- Lawrence Rosen
22+
osi_license_key: AFL-3.0

src/licensedcode/data/licenses/agpl-3.0.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ ignorable_holders:
2727
ignorable_urls:
2828
- https://fsf.org/
2929
- https://www.gnu.org/licenses/
30+
osi_license_key: AGPL-3.0

src/licensedcode/data/licenses/apache-1.1.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,4 @@ ignorable_urls:
2424
- http://www.apache.org/
2525
ignorable_emails:
2626
- apache@apache.org
27+
osi_license_key: Apache-1.1

src/licensedcode/data/licenses/apache-2.0.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,4 @@ other_urls:
1818
ignorable_urls:
1919
- http://www.apache.org/licenses/
2020
- http://www.apache.org/licenses/LICENSE-2.0
21+
osi_license_key: Apache-2.0

src/licensedcode/data/licenses/apsl-2.0.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ ignorable_holders:
1919
ignorable_urls:
2020
- http://www.apple.com/legal/guidelinesfor3rdparties.html
2121
- http://www.opensource.apple.com/apsl/
22+
osi_license_key: APSL-2.0

src/licensedcode/data/licenses/artistic-1.0.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ other_urls:
1616
- https://opensource.org/licenses/Artistic-1.0
1717
ignorable_urls:
1818
- http://ftp.uu.net/
19+
osi_license_key: Artistic-1.0

src/licensedcode/data/licenses/artistic-2.0.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,4 @@ ignorable_authors:
2222
- The Perl Foundation
2323
ignorable_holders:
2424
- The Perl Foundation
25+
osi_license_key: Artistic-2.0

src/licensedcode/data/licenses/bsd-new.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,4 @@ osi_url: http://www.opensource.org/licenses/BSD-3-Clause
1212
other_urls:
1313
- http://framework.zend.com/license/new-bsd
1414
- https://opensource.org/licenses/BSD-3-Clause
15+
osi_license_key: BSD-3

0 commit comments

Comments
 (0)