Skip to content

Commit

Permalink
Use the JSON license list
Browse files Browse the repository at this point in the history
Signed-off-by: Philippe Ombredanne <[email protected]>
  • Loading branch information
pombredanne committed Jun 15, 2017
1 parent 3a4d0c5 commit 462e986
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 372 deletions.
29 changes: 20 additions & 9 deletions spdx/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,35 @@
from __future__ import unicode_literals

import codecs
import json
import os

from spdx.version import Version

_base_dir = os.path.dirname(__file__)
_licenses = os.path.join(_base_dir, 'licenses.json')
_exceptions = os.path.join(_base_dir, 'exceptions.json')

def load_license_list(file_name=os.path.join(os.path.dirname(__file__), 'spdx_licenselist.csv')):

def load_license_list(file_name):
"""
Return a mapping of licenses name->id and id->name loaded from a
CSV file as "name,identifier"
Return the licenses list version tuple and a mapping of licenses
name->id and id->name loaded from a JSON file
from https://github.com/spdx/license-list-data
"""
licenses_map = {}
with codecs.open(file_name, 'rb', encoding='utf-8') as licenses:
for line in licenses:
name, identifier = line.strip().split(',')
with codecs.open(file_name, 'rb', encoding='utf-8') as lics:
licenses = json.load(lics)
version = licenses['licenseListVersion'].split('.')
for lic in licenses['licenses']:
if lic.get('isDeprecatedLicenseId'):
continue
name = lic['name']
identifier = lic['licenseId']
licenses_map[name] = identifier
licenses_map[identifier] = name
return licenses_map
return version, licenses_map


LICENSE_MAP = load_license_list()
LICENSE_LIST_VERSION = Version(major=2, minor=25)
(_major, _minor), LICENSE_MAP = load_license_list(_licenses)
LICENSE_LIST_VERSION = Version(major=_major, minor=_minor)
1 change: 1 addition & 0 deletions spdx/licenses.json

Large diffs are not rendered by default.

Loading

0 comments on commit 462e986

Please sign in to comment.