|
15 | 15 | from __future__ import unicode_literals
|
16 | 16 |
|
17 | 17 | import codecs
|
| 18 | +import json |
18 | 19 | import os
|
19 | 20 |
|
20 | 21 | from spdx.version import Version
|
21 | 22 |
|
| 23 | +_base_dir = os.path.dirname(__file__) |
| 24 | +_licenses = os.path.join(_base_dir, 'licenses.json') |
| 25 | +_exceptions = os.path.join(_base_dir, 'exceptions.json') |
22 | 26 |
|
23 |
| -def load_license_list(file_name=os.path.join(os.path.dirname(__file__), 'spdx_licenselist.csv')): |
| 27 | + |
| 28 | +def load_license_list(file_name): |
24 | 29 | """
|
25 |
| - Return a mapping of licenses name->id and id->name loaded from a |
26 |
| - CSV file as "name,identifier" |
| 30 | + Return the licenses list version tuple and a mapping of licenses |
| 31 | + name->id and id->name loaded from a JSON file |
| 32 | + from https://github.com/spdx/license-list-data |
27 | 33 | """
|
28 | 34 | licenses_map = {}
|
29 |
| - with codecs.open(file_name, 'rb', encoding='utf-8') as licenses: |
30 |
| - for line in licenses: |
31 |
| - name, identifier = line.strip().split(',') |
| 35 | + with codecs.open(file_name, 'rb', encoding='utf-8') as lics: |
| 36 | + licenses = json.load(lics) |
| 37 | + version = licenses['licenseListVersion'].split('.') |
| 38 | + for lic in licenses['licenses']: |
| 39 | + if lic.get('isDeprecatedLicenseId'): |
| 40 | + continue |
| 41 | + name = lic['name'] |
| 42 | + identifier = lic['licenseId'] |
32 | 43 | licenses_map[name] = identifier
|
33 | 44 | licenses_map[identifier] = name
|
34 |
| - return licenses_map |
| 45 | + return version, licenses_map |
35 | 46 |
|
36 | 47 |
|
37 |
| -LICENSE_MAP = load_license_list() |
38 |
| -LICENSE_LIST_VERSION = Version(major=2, minor=25) |
| 48 | +(_major, _minor), LICENSE_MAP = load_license_list(_licenses) |
| 49 | +LICENSE_LIST_VERSION = Version(major=_major, minor=_minor) |
0 commit comments