Skip to content

Commit

Permalink
Merge pull request #33 from fosslight/develop
Browse files Browse the repository at this point in the history
Add the function to write opossum format result file and modify the function write result file.
  • Loading branch information
dd-jy authored Oct 15, 2021
2 parents dff15f8 + 90ab7f2 commit 02535f9
Show file tree
Hide file tree
Showing 13 changed files with 8,918 additions and 34 deletions.
8 changes: 8 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,11 @@ License: Apache-2.0
Files: .bumpversion.cfg
Copyright: 2021 LG Electronics
License: Apache-2.0

Files: src/fosslight_util/frequentLicenselist.json
Copyright: 2021 LG Electronics
License: Apache-2.0

Files: src/fosslight_util/licenses.json
Copyright: SPDX
License: CC-BY-3.0
93 changes: 93 additions & 0 deletions LICENSES/CC-BY-3.0.txt

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,5 @@ tox
pytest
pytest-cov
pytest-flake8
flake8==3.9.2
tox-wheel
2 changes: 2 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@
"Programming Language :: Python :: 3.8",
"Programming Language :: Python :: 3.9", ],
install_requires=required,
package_data={'fosslight_util': ['frequentLicenselist.json']},
include_package_data=True,
entry_points={
"console_scripts": [
"fosslight_download = fosslight_util.download:main",
Expand Down
67 changes: 67 additions & 0 deletions src/fosslight_util/_create_frequenctLicenses.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (c) 2021 LG Electronics Inc.
# SPDX-License-Identifier: Apache-2.0

from urllib.request import urlopen
import os
import json
import traceback


def create_frequentlicenses():
success = True
error_msg = ''
licenses = ''
licenses_file = 'licenses.json'
frequentLicenses = {}
_frequentLicenses_key = 'frequentLicenses'

# spdx_txt_url = _spdx_txt_base_url + version + /text/ + licenseId + '.txt'
_spdx_txt_base_url = 'https://raw.githubusercontent.com/spdx/license-list-data/'

base_dir = os.path.dirname(__file__)
# https://github.com/spdx/license-list-data/blob/v3.14/json/licenses.json
file_withpath = os.path.join(base_dir, licenses_file)

try:
with open(file_withpath, 'r') as f:
licenses = json.load(f)
version = licenses['licenseListVersion']
frequentLicenses[_frequentLicenses_key] = []
for lic in licenses['licenses']:
tmp_lic = {}
tmp_lic["fullName"] = lic['name']
tmp_lic["shortName"] = lic['licenseId']

deprecated = lic['isDeprecatedLicenseId']
if deprecated:
spdx_txt_url = _spdx_txt_base_url + 'v' + version + '/text/' + 'deprecated_' + lic['licenseId'] + '.txt'
else:
spdx_txt_url = _spdx_txt_base_url + 'v' + version + '/text/' + lic['licenseId'] + '.txt'

with urlopen(spdx_txt_url) as url:
licenseText = url.read().decode('utf-8')
tmp_lic["defaultText"] = licenseText

frequentLicenses[_frequentLicenses_key].append(tmp_lic)

except Exception as e:
success = False
error_msg = 'Failed to open and parse ' + licenses_file
print(error_msg, ": ", e)
print(traceback.format_exc())

return frequentLicenses, success, error_msg


def main():
_frequencyLicense = 'frequentLicenselist.json'
frequentLicenses, success, error_msg = create_frequentlicenses()
if success:
with open(_frequencyLicense, 'w', encoding='utf-8') as f:
json.dump(frequentLicenses, f, sort_keys=True, indent=4)


if __name__ == '__main__':
main()
2,374 changes: 2,374 additions & 0 deletions src/fosslight_util/frequentLicenselist.json

Large diffs are not rendered by default.

Loading

0 comments on commit 02535f9

Please sign in to comment.