Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python.pythonPath": "/home/sarthak/gsoc/aboutcode-toolkit/local/bin/python2.7"
Comment thread
chinyeungli marked this conversation as resolved.
Outdated
}
8 changes: 8 additions & 0 deletions src/attributecode/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,14 @@ def transform_json(data, transformer):
errors = []
new_data = []
renamings = transformer.column_renamings
#if json is output of scancode-toolkit
if(data["headers"][0]["tool_name"] == "scancode-toolkit"):
#only takes data inside "files"
data = data["files"]
#automatically renames path to about_resource
if("path" not in renamings.keys()):
renamings["path"] = "about_resource"
Comment thread
chinyeungli marked this conversation as resolved.
Outdated

if isinstance(data, list):
for item in data:
element, err = process_json_keys(item, renamings, transformer)
Expand Down
15 changes: 14 additions & 1 deletion tests/test_transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,17 @@ def test_transform_data_json_as_array(self):
for item in data:
keys = list(item.keys())
expect = [u'about_resource', u'name', u'version']
assert keys == expect
assert keys == expect

def test_transform_data_json_scancode(self):
test_file = get_test_loc('test_transform/input_scancode.json')
configuration = get_test_loc('test_transform/configuration_scancode')
json_data = read_json(test_file)
transformer = Transformer.from_file(configuration)
data, err = transform_json(json_data, transformer)
keys = []
for item in data:
keys = list(item.keys())
expect = [u'about_resource', u'name', u'new_extension']
assert keys == expect

11 changes: 11 additions & 0 deletions tests/testdata/test_transform/configuration_scancode
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
column_renamings:
extension : new_extension
column_filters:
- name
- new_extension
- about_resource
required_columns:
- name
- type


Loading