Skip to content

Commit c9aa567

Browse files
committed
Use plain codecs to load the license list. Bump version spdx#11
* do not use CSV for a file that does not need it. * the first header line of the CVS was also removed Signed-off-by: Philippe Ombredanne <pombredanne@nexb.com>
1 parent dce58f5 commit c9aa567

File tree

5 files changed

+15
-54
lines changed

5 files changed

+15
-54
lines changed

data/sample.csv

Lines changed: 0 additions & 2 deletions
This file was deleted.

setup.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def test_suite():
1313

1414
setup(
1515
name='spdx-tools',
16-
version='0.5.0',
16+
version='0.5.1',
1717
description='SPDX parser and tools.',
1818
packages=['spdx', 'spdx.parsers', 'spdx.writers', 'spdx.parsers.lexers'],
1919
package_data={'spdx': ['spdx_licenselist.csv']},
@@ -23,7 +23,7 @@ def test_suite():
2323
install_requires=[
2424
'ply',
2525
'rdflib',
26-
'six'
26+
'six',
2727
],
2828
entry_points={
2929
'console_scripts': [

spdx/config.py

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,24 @@
1414
from __future__ import print_function
1515
from __future__ import unicode_literals
1616

17-
import csv
17+
import codecs
1818
import os
1919

2020
from spdx.version import Version
2121

2222

23-
class TwoWayDict(dict):
24-
25-
def __setitem__(self, key, value):
26-
dict.__setitem__(self, key, value)
27-
dict.__setitem__(self, value, key)
28-
29-
def __delitem__(self, key):
30-
dict.__delitem__(self, self[key])
31-
dict.__delitem__(self, key)
32-
33-
34-
def load_license_list():
35-
file_name = os.path.join(os.path.dirname(__file__), 'spdx_licenselist.csv')
36-
with open(file_name, 'r') as file_in:
37-
reader = csv.DictReader(file_in)
38-
dct = TwoWayDict()
39-
for entry in reader:
40-
dct[entry['Full name of License']] = entry['License Identifier']
41-
return dct
23+
def load_license_list(file_name=os.path.join(os.path.dirname(__file__), 'spdx_licenselist.csv')):
24+
"""
25+
Return a mapping of licenses name->id and id->name loaded from a
26+
CSV file as "name,identifier"
27+
"""
28+
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(',')
32+
licenses_map[name] = identifier
33+
licenses_map[identifier] = name
34+
return licenses_map
4235

4336

4437
LICENSE_MAP = load_license_list()

spdx/spdx_licenselist.csv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
Full name of License,License Identifier
21
3dfx Glide License,Glide
32
Abstyles License,Abstyles
43
Academic Free License v1.1,AFL-1.1

tests/test_unicodecsv.py

Lines changed: 0 additions & 29 deletions
This file was deleted.

0 commit comments

Comments
 (0)