Skip to content

Commit 02535f9

Browse files
authored
Merge pull request #33 from fosslight/develop
Add the function to write opossum format result file and modify the function write result file.
2 parents dff15f8 + 90ab7f2 commit 02535f9

File tree

13 files changed

+8918
-34
lines changed

13 files changed

+8918
-34
lines changed

.reuse/dep5

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ License: Apache-2.0
2121
Files: .bumpversion.cfg
2222
Copyright: 2021 LG Electronics
2323
License: Apache-2.0
24+
25+
Files: src/fosslight_util/frequentLicenselist.json
26+
Copyright: 2021 LG Electronics
27+
License: Apache-2.0
28+
29+
Files: src/fosslight_util/licenses.json
30+
Copyright: SPDX
31+
License: CC-BY-3.0

LICENSES/CC-BY-3.0.txt

Lines changed: 93 additions & 0 deletions
Large diffs are not rendered by default.

requirements-dev.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ tox
22
pytest
33
pytest-cov
44
pytest-flake8
5+
flake8==3.9.2
6+
tox-wheel

setup.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
"Programming Language :: Python :: 3.8",
3232
"Programming Language :: Python :: 3.9", ],
3333
install_requires=required,
34+
package_data={'fosslight_util': ['frequentLicenselist.json']},
35+
include_package_data=True,
3436
entry_points={
3537
"console_scripts": [
3638
"fosslight_download = fosslight_util.download:main",
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
#!/usr/bin/env python
2+
# -*- coding: utf-8 -*-
3+
# Copyright (c) 2021 LG Electronics Inc.
4+
# SPDX-License-Identifier: Apache-2.0
5+
6+
from urllib.request import urlopen
7+
import os
8+
import json
9+
import traceback
10+
11+
12+
def create_frequentlicenses():
13+
success = True
14+
error_msg = ''
15+
licenses = ''
16+
licenses_file = 'licenses.json'
17+
frequentLicenses = {}
18+
_frequentLicenses_key = 'frequentLicenses'
19+
20+
# spdx_txt_url = _spdx_txt_base_url + version + /text/ + licenseId + '.txt'
21+
_spdx_txt_base_url = 'https://raw.githubusercontent.com/spdx/license-list-data/'
22+
23+
base_dir = os.path.dirname(__file__)
24+
# https://github.com/spdx/license-list-data/blob/v3.14/json/licenses.json
25+
file_withpath = os.path.join(base_dir, licenses_file)
26+
27+
try:
28+
with open(file_withpath, 'r') as f:
29+
licenses = json.load(f)
30+
version = licenses['licenseListVersion']
31+
frequentLicenses[_frequentLicenses_key] = []
32+
for lic in licenses['licenses']:
33+
tmp_lic = {}
34+
tmp_lic["fullName"] = lic['name']
35+
tmp_lic["shortName"] = lic['licenseId']
36+
37+
deprecated = lic['isDeprecatedLicenseId']
38+
if deprecated:
39+
spdx_txt_url = _spdx_txt_base_url + 'v' + version + '/text/' + 'deprecated_' + lic['licenseId'] + '.txt'
40+
else:
41+
spdx_txt_url = _spdx_txt_base_url + 'v' + version + '/text/' + lic['licenseId'] + '.txt'
42+
43+
with urlopen(spdx_txt_url) as url:
44+
licenseText = url.read().decode('utf-8')
45+
tmp_lic["defaultText"] = licenseText
46+
47+
frequentLicenses[_frequentLicenses_key].append(tmp_lic)
48+
49+
except Exception as e:
50+
success = False
51+
error_msg = 'Failed to open and parse ' + licenses_file
52+
print(error_msg, ": ", e)
53+
print(traceback.format_exc())
54+
55+
return frequentLicenses, success, error_msg
56+
57+
58+
def main():
59+
_frequencyLicense = 'frequentLicenselist.json'
60+
frequentLicenses, success, error_msg = create_frequentlicenses()
61+
if success:
62+
with open(_frequencyLicense, 'w', encoding='utf-8') as f:
63+
json.dump(frequentLicenses, f, sort_keys=True, indent=4)
64+
65+
66+
if __name__ == '__main__':
67+
main()

src/fosslight_util/frequentLicenselist.json

Lines changed: 2374 additions & 0 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)