Skip to content

Commit 1c48705

Browse files
committed
Remove mapping_output feature
Mapping can now only be used when using a CSV as an input. Signed-off-by: Philippe Ombredanne <[email protected]>
1 parent 851aa4f commit 1c48705

File tree

4 files changed

+5
-61
lines changed

4 files changed

+5
-61
lines changed

src/attributecode/model.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1358,25 +1358,19 @@ def about_object_to_list_of_dictionary(abouts, with_absent=False, with_empty=Tru
13581358
return abouts_dictionary_list
13591359

13601360

1361-
def write_output(abouts, location, format, mapping_output=None, with_absent=False, with_empty=True): # NOQA
1361+
def write_output(abouts, location, format, with_absent=False, with_empty=True): # NOQA
13621362
"""
1363-
Write a CSV/JSON file at location given a list of About objects
1363+
Write a CSV/JSON file at location given a list of About objects.
1364+
Return a list of Error objects.
13641365
"""
13651366
errors = []
13661367
about_dictionary_list = about_object_to_list_of_dictionary(abouts, with_absent, with_empty)
1367-
if mapping_output:
1368-
updated_dictionary_list = util.update_about_dictionary_keys(about_dictionary_list, mapping_output)
1369-
else:
1370-
updated_dictionary_list = about_dictionary_list
1368+
updated_dictionary_list = about_dictionary_list
13711369
location = add_unc(location)
13721370
with codecs.open(location, mode='wb', encoding='utf-8') as output_file:
13731371
if format == 'csv':
13741372
fieldnames = field_names(abouts)
1375-
if mapping_output:
1376-
updated_fieldnames = util.update_fieldnames(fieldnames, mapping_output)
1377-
else:
1378-
updated_fieldnames = fieldnames
1379-
writer = csv.DictWriter(output_file, updated_fieldnames)
1373+
writer = csv.DictWriter(output_file, fieldnames)
13801374
writer.writeheader()
13811375
csv_formatted_list = util.format_about_dict_for_csv_output(updated_dictionary_list)
13821376
for row in csv_formatted_list:

src/attributecode/util.py

Lines changed: 0 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -658,40 +658,6 @@ def inventory_filter(abouts, filters):
658658
return matching_abouts
659659

660660

661-
# FIXME: rename function: this is mapping field names. Also this is returning a list...
662-
# since the list should contain NO duplicate, it would be best to simply return an
663-
# ordered mapping {old name: new name}
664-
def update_fieldnames(field_names, mapping_location):
665-
"""
666-
Given a `field_names` list of field names and a `mapping_location` mapping
667-
configuration file location, return a list of updated field names
668-
"""
669-
mapping = get_mapping(mapping_location, lowercase=False)
670-
updated_names = []
671-
for name in field_names:
672-
if name in mapping:
673-
name = mapping[name]
674-
updated_names.append(name)
675-
return updated_names
676-
677-
678-
# FIXME: add docstring
679-
def update_about_dictionary_keys(about_dictionary_list, mapping_output):
680-
output_map = get_mapping(mapping_output, lowercase=False)
681-
updated_dict_list = []
682-
for element in about_dictionary_list:
683-
updated_ordered_dict = OrderedDict()
684-
for about_key, value in element.items():
685-
update_key = False
686-
for custom_key in output_map:
687-
if about_key == custom_key:
688-
update_key = True
689-
updated_ordered_dict[output_map[custom_key]] = value
690-
break
691-
if not update_key:
692-
updated_ordered_dict[about_key] = value
693-
updated_dict_list.append(updated_ordered_dict)
694-
return updated_dict_list
695661

696662

697663
# FIXME: we should use a license object instead

tests/test_util.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -369,21 +369,6 @@ def test_load_mapping_only_load_last_instance_of_duplicated_keys(self):
369369
expected = OrderedDict([(u'descr', u'description3'), (u'other', u'bar')])
370370
assert expected == result
371371

372-
def test_update_fieldnames(self):
373-
mapping_loc = get_test_loc('test_util/mapping/fieldnames_mapping.config')
374-
field_names = ['about_file_path', 'name', 'version']
375-
expected = ['about_file_path', 'Component', 'version']
376-
result = util.update_fieldnames(field_names, mapping_loc)
377-
assert expected == result
378-
379-
def test_update_about_dictionary_keys(self):
380-
mapping_loc = get_test_loc('test_util/mapping/fieldnames_mapping.config')
381-
abouts = [dict(name='test.c')]
382-
expected = [dict(Component='test.c')]
383-
result = util.update_about_dictionary_keys(abouts, mapping_loc)
384-
assert expected == result
385-
386-
387372

388373
class TestCsv(unittest.TestCase):
389374

tests/testdata/test_util/mapping/fieldnames_mapping.config

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)