Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
37 changes: 31 additions & 6 deletions src/deltacode/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,22 +168,31 @@ def __init__(self, new_file=None, old_file=None, delta_type=None):
self.old_file = old_file if old_file else File()
self.category = delta_type if delta_type else ''

# Change the Delta object's 'category' attribute to
# 'license change' if a substantial license change has been detected.
# If a license change is detected, and depending on the nature of that change,
# change the Delta object's 'category' attribute from 'modified' to
# 'license change', 'license info removed' or 'license info added'.
if self.category == 'modified':
self._license_diff()

def _license_diff(self, cutoff_score=50):
"""
Compare the license details for a pair of 'new' and 'old' File objects
in a Delta object and change the Delta object's 'category' attribute to
'license change' if those details differ and the cutoff score test is
satisfied.
'license info removed', 'license info added' or 'license change' if
there has been a license change and depending on the nature of that change.
"""
new_licenses = self.new_file.licenses or []
new_keys = set(l.key for l in new_licenses if l.score >= cutoff_score)

old_licenses = self.old_file.licenses or []

if len(self.new_file.licenses) > 0 and self.old_file.licenses == []:
self.category = 'license info added'
return

if self.new_file.licenses == [] and len(self.old_file.licenses) > 0:
self.category = 'license info removed'
return

new_keys = set(l.key for l in new_licenses if l.score >= cutoff_score)
old_keys = set(l.key for l in old_licenses if l.score >= cutoff_score)

if new_keys != old_keys:
Expand Down Expand Up @@ -226,6 +235,22 @@ def to_dict(self):
('type', self.new_file.type),
('size', self.new_file.size)
])
elif self.category == 'license info added':
return OrderedDict([
('category', 'license info added'),
('path', self.new_file.path),
('name', self.new_file.name),
('type', self.new_file.type),
('size', self.new_file.size)
])
elif self.category == 'license info removed':
return OrderedDict([
('category', 'license info removed'),
('path', self.new_file.path),
('name', self.new_file.name),
('type', self.new_file.type),
('size', self.new_file.size)
])
else:
return OrderedDict([
('category', 'unmodified'),
Expand Down
3 changes: 3 additions & 0 deletions tests/data/cli/license_info_added.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Type of delta,Path,Name,Type,Size
license info added,some/path/a/a1.py,a1.py,file,350
unmodified,some/path/b/b1.py,b1.py,file,290
3 changes: 3 additions & 0 deletions tests/data/cli/license_info_added_below_cutoff_score.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Type of delta,Path,Name,Type,Size
license info added,some/path/a/a1.py,a1.py,file,350
unmodified,some/path/b/b1.py,b1.py,file,290
3 changes: 3 additions & 0 deletions tests/data/cli/license_info_removed.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Type of delta,Path,Name,Type,Size
license info removed,some/path/a/a1.py,a1.py,file,350
unmodified,some/path/b/b1.py,b1.py,file,290
3 changes: 3 additions & 0 deletions tests/data/cli/license_info_removed_below_cutoff_score.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Type of delta,Path,Name,Type,Size
license info removed,some/path/a/a1.py,a1.py,file,350
unmodified,some/path/b/b1.py,b1.py,file,290
41 changes: 41 additions & 0 deletions tests/data/cli/scan_new_license_info_added.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"scancode_notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
"scancode_version": "2.1.0",
"scancode_options": {
"--license": true,
"--info": true
},
"files_count": 2,
"files": [
{
"path": "some/path/a/a1.py",
"type": "file",
"name": "a1.py",
"size": 350,
"sha1": "222647771481d39dd3a53f6dc210c26abac37748",
"licenses": [
{
"key": "apache-2.0",
"score": 80.0,
"short_name": "Apache 2.0",
"category": "Permissive"
}
]
},
{
"path": "some/path/b/b1.py",
"type": "file",
"name": "b1.py",
"size": 290,
"sha1": "333647771481d39dd3a53f6dc210c26abac37748",
"licenses": [
{
"key": "mit",
"score": 100.0,
"short_name": "MIT License",
"category": "Permissive"
}
]
}
]
}
41 changes: 41 additions & 0 deletions tests/data/cli/scan_new_license_info_added_below_cutoff_score.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"scancode_notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
"scancode_version": "2.1.0",
"scancode_options": {
"--license": true,
"--info": true
},
"files_count": 2,
"files": [
{
"path": "some/path/a/a1.py",
"type": "file",
"name": "a1.py",
"size": 350,
"sha1": "222647771481d39dd3a53f6dc210c26abac37748",
"licenses": [
{
"key": "apache-2.0",
"score": 49.0,
"short_name": "Apache 2.0",
"category": "Permissive"
}
]
},
{
"path": "some/path/b/b1.py",
"type": "file",
"name": "b1.py",
"size": 290,
"sha1": "333647771481d39dd3a53f6dc210c26abac37748",
"licenses": [
{
"key": "mit",
"score": 100.0,
"short_name": "MIT License",
"category": "Permissive"
}
]
}
]
}
34 changes: 34 additions & 0 deletions tests/data/cli/scan_new_license_info_removed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"scancode_notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
"scancode_version": "2.1.0",
"scancode_options": {
"--license": true,
"--info": true
},
"files_count": 2,
"files": [
{
"path": "some/path/a/a1.py",
"type": "file",
"name": "a1.py",
"size": 350,
"sha1": "222647771481d39dd3a53f6dc210c26abac37748",
"licenses": []
},
{
"path": "some/path/b/b1.py",
"type": "file",
"name": "b1.py",
"size": 290,
"sha1": "333647771481d39dd3a53f6dc210c26abac37748",
"licenses": [
{
"key": "mit",
"score": 100.0,
"short_name": "MIT License",
"category": "Permissive"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"scancode_notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
"scancode_version": "2.1.0",
"scancode_options": {
"--license": true,
"--info": true
},
"files_count": 2,
"files": [
{
"path": "some/path/a/a1.py",
"type": "file",
"name": "a1.py",
"size": 350,
"sha1": "222647771481d39dd3a53f6dc210c26abac37748",
"licenses": []
},
{
"path": "some/path/b/b1.py",
"type": "file",
"name": "b1.py",
"size": 290,
"sha1": "333647771481d39dd3a53f6dc210c26abac37748",
"licenses": [
{
"key": "mit",
"score": 100.0,
"short_name": "MIT License",
"category": "Permissive"
}
]
}
]
}
34 changes: 34 additions & 0 deletions tests/data/cli/scan_old_license_info_added.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"scancode_notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
"scancode_version": "2.1.0",
"scancode_options": {
"--license": true,
"--info": true
},
"files_count": 2,
"files": [
{
"path": "some/path/a/a1.py",
"type": "file",
"name": "a1.py",
"size": 300,
"sha1": "000647771481d39dd3a53f6dc210c26abac37748",
"licenses": []
},
{
"path": "some/path/b/b1.py",
"type": "file",
"name": "b1.py",
"size": 290,
"sha1": "333647771481d39dd3a53f6dc210c26abac37748",
"licenses": [
{
"key": "mit",
"score": 100.0,
"short_name": "MIT License",
"category": "Permissive"
}
]
}
]
}
34 changes: 34 additions & 0 deletions tests/data/cli/scan_old_license_info_added_below_cutoff_score.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"scancode_notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
"scancode_version": "2.1.0",
"scancode_options": {
"--license": true,
"--info": true
},
"files_count": 2,
"files": [
{
"path": "some/path/a/a1.py",
"type": "file",
"name": "a1.py",
"size": 300,
"sha1": "000647771481d39dd3a53f6dc210c26abac37748",
"licenses": []
},
{
"path": "some/path/b/b1.py",
"type": "file",
"name": "b1.py",
"size": 290,
"sha1": "333647771481d39dd3a53f6dc210c26abac37748",
"licenses": [
{
"key": "mit",
"score": 100.0,
"short_name": "MIT License",
"category": "Permissive"
}
]
}
]
}
41 changes: 41 additions & 0 deletions tests/data/cli/scan_old_license_info_removed.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"scancode_notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
"scancode_version": "2.1.0",
"scancode_options": {
"--license": true,
"--info": true
},
"files_count": 2,
"files": [
{
"path": "some/path/a/a1.py",
"type": "file",
"name": "a1.py",
"size": 300,
"sha1": "000647771481d39dd3a53f6dc210c26abac37748",
"licenses": [
{
"key": "apache-2.0",
"score": 80.0,
"short_name": "Apache 2.0",
"category": "Permissive"
}
]
},
{
"path": "some/path/b/b1.py",
"type": "file",
"name": "b1.py",
"size": 290,
"sha1": "333647771481d39dd3a53f6dc210c26abac37748",
"licenses": [
{
"key": "mit",
"score": 100.0,
"short_name": "MIT License",
"category": "Permissive"
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"scancode_notice": "Generated with ScanCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nScanCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nScanCode is a free software code scanning tool from nexB Inc. and others.\nVisit https://github.com/nexB/scancode-toolkit/ for support and download.",
"scancode_version": "2.1.0",
"scancode_options": {
"--license": true,
"--info": true
},
"files_count": 2,
"files": [
{
"path": "some/path/a/a1.py",
"type": "file",
"name": "a1.py",
"size": 300,
"sha1": "000647771481d39dd3a53f6dc210c26abac37748",
"licenses": [
{
"key": "apache-2.0",
"score": 49.0,
"short_name": "Apache 2.0",
"category": "Permissive"
}
]
},
{
"path": "some/path/b/b1.py",
"type": "file",
"name": "b1.py",
"size": 290,
"sha1": "333647771481d39dd3a53f6dc210c26abac37748",
"licenses": [
{
"key": "mit",
"score": 100.0,
"short_name": "MIT License",
"category": "Permissive"
}
]
}
]
}
Loading