Skip to content

Commit 9a963f4

Browse files
authored
Merge pull request #39 from nexB/29-license-info-added-removed
Determine whether license info added/removed #29
2 parents 0c5fe02 + c36b72b commit 9a963f4

15 files changed

Lines changed: 405 additions & 20 deletions

src/deltacode/__init__.py

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,31 @@ def __init__(self, new_file=None, old_file=None, delta_type=None):
168168
self.old_file = old_file if old_file else File()
169169
self.category = delta_type if delta_type else ''
170170

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

176177
def _license_diff(self, cutoff_score=50):
177178
"""
178179
Compare the license details for a pair of 'new' and 'old' File objects
179180
in a Delta object and change the Delta object's 'category' attribute to
180-
'license change' if those details differ and the cutoff score test is
181-
satisfied.
181+
'license info removed', 'license info added' or 'license change' if
182+
there has been a license change and depending on the nature of that change.
182183
"""
183184
new_licenses = self.new_file.licenses or []
184-
new_keys = set(l.key for l in new_licenses if l.score >= cutoff_score)
185-
186185
old_licenses = self.old_file.licenses or []
186+
187+
if len(self.new_file.licenses) > 0 and self.old_file.licenses == []:
188+
self.category = 'license info added'
189+
return
190+
191+
if self.new_file.licenses == [] and len(self.old_file.licenses) > 0:
192+
self.category = 'license info removed'
193+
return
194+
195+
new_keys = set(l.key for l in new_licenses if l.score >= cutoff_score)
187196
old_keys = set(l.key for l in old_licenses if l.score >= cutoff_score)
188197

189198
if new_keys != old_keys:
@@ -226,6 +235,22 @@ def to_dict(self):
226235
('type', self.new_file.type),
227236
('size', self.new_file.size)
228237
])
238+
elif self.category == 'license info added':
239+
return OrderedDict([
240+
('category', 'license info added'),
241+
('path', self.new_file.path),
242+
('name', self.new_file.name),
243+
('type', self.new_file.type),
244+
('size', self.new_file.size)
245+
])
246+
elif self.category == 'license info removed':
247+
return OrderedDict([
248+
('category', 'license info removed'),
249+
('path', self.new_file.path),
250+
('name', self.new_file.name),
251+
('type', self.new_file.type),
252+
('size', self.new_file.size)
253+
])
229254
else:
230255
return OrderedDict([
231256
('category', 'unmodified'),
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Type of delta,Path,Name,Type,Size
2+
license info added,some/path/a/a1.py,a1.py,file,350
3+
unmodified,some/path/b/b1.py,b1.py,file,290
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Type of delta,Path,Name,Type,Size
2+
license info added,some/path/a/a1.py,a1.py,file,350
3+
unmodified,some/path/b/b1.py,b1.py,file,290
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Type of delta,Path,Name,Type,Size
2+
license info removed,some/path/a/a1.py,a1.py,file,350
3+
unmodified,some/path/b/b1.py,b1.py,file,290
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Type of delta,Path,Name,Type,Size
2+
license info removed,some/path/a/a1.py,a1.py,file,350
3+
unmodified,some/path/b/b1.py,b1.py,file,290
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"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.",
3+
"scancode_version": "2.1.0",
4+
"scancode_options": {
5+
"--license": true,
6+
"--info": true
7+
},
8+
"files_count": 2,
9+
"files": [
10+
{
11+
"path": "some/path/a/a1.py",
12+
"type": "file",
13+
"name": "a1.py",
14+
"size": 350,
15+
"sha1": "222647771481d39dd3a53f6dc210c26abac37748",
16+
"licenses": [
17+
{
18+
"key": "apache-2.0",
19+
"score": 80.0,
20+
"short_name": "Apache 2.0",
21+
"category": "Permissive"
22+
}
23+
]
24+
},
25+
{
26+
"path": "some/path/b/b1.py",
27+
"type": "file",
28+
"name": "b1.py",
29+
"size": 290,
30+
"sha1": "333647771481d39dd3a53f6dc210c26abac37748",
31+
"licenses": [
32+
{
33+
"key": "mit",
34+
"score": 100.0,
35+
"short_name": "MIT License",
36+
"category": "Permissive"
37+
}
38+
]
39+
}
40+
]
41+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"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.",
3+
"scancode_version": "2.1.0",
4+
"scancode_options": {
5+
"--license": true,
6+
"--info": true
7+
},
8+
"files_count": 2,
9+
"files": [
10+
{
11+
"path": "some/path/a/a1.py",
12+
"type": "file",
13+
"name": "a1.py",
14+
"size": 350,
15+
"sha1": "222647771481d39dd3a53f6dc210c26abac37748",
16+
"licenses": [
17+
{
18+
"key": "apache-2.0",
19+
"score": 49.0,
20+
"short_name": "Apache 2.0",
21+
"category": "Permissive"
22+
}
23+
]
24+
},
25+
{
26+
"path": "some/path/b/b1.py",
27+
"type": "file",
28+
"name": "b1.py",
29+
"size": 290,
30+
"sha1": "333647771481d39dd3a53f6dc210c26abac37748",
31+
"licenses": [
32+
{
33+
"key": "mit",
34+
"score": 100.0,
35+
"short_name": "MIT License",
36+
"category": "Permissive"
37+
}
38+
]
39+
}
40+
]
41+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"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.",
3+
"scancode_version": "2.1.0",
4+
"scancode_options": {
5+
"--license": true,
6+
"--info": true
7+
},
8+
"files_count": 2,
9+
"files": [
10+
{
11+
"path": "some/path/a/a1.py",
12+
"type": "file",
13+
"name": "a1.py",
14+
"size": 350,
15+
"sha1": "222647771481d39dd3a53f6dc210c26abac37748",
16+
"licenses": []
17+
},
18+
{
19+
"path": "some/path/b/b1.py",
20+
"type": "file",
21+
"name": "b1.py",
22+
"size": 290,
23+
"sha1": "333647771481d39dd3a53f6dc210c26abac37748",
24+
"licenses": [
25+
{
26+
"key": "mit",
27+
"score": 100.0,
28+
"short_name": "MIT License",
29+
"category": "Permissive"
30+
}
31+
]
32+
}
33+
]
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"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.",
3+
"scancode_version": "2.1.0",
4+
"scancode_options": {
5+
"--license": true,
6+
"--info": true
7+
},
8+
"files_count": 2,
9+
"files": [
10+
{
11+
"path": "some/path/a/a1.py",
12+
"type": "file",
13+
"name": "a1.py",
14+
"size": 350,
15+
"sha1": "222647771481d39dd3a53f6dc210c26abac37748",
16+
"licenses": []
17+
},
18+
{
19+
"path": "some/path/b/b1.py",
20+
"type": "file",
21+
"name": "b1.py",
22+
"size": 290,
23+
"sha1": "333647771481d39dd3a53f6dc210c26abac37748",
24+
"licenses": [
25+
{
26+
"key": "mit",
27+
"score": 100.0,
28+
"short_name": "MIT License",
29+
"category": "Permissive"
30+
}
31+
]
32+
}
33+
]
34+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
{
2+
"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.",
3+
"scancode_version": "2.1.0",
4+
"scancode_options": {
5+
"--license": true,
6+
"--info": true
7+
},
8+
"files_count": 2,
9+
"files": [
10+
{
11+
"path": "some/path/a/a1.py",
12+
"type": "file",
13+
"name": "a1.py",
14+
"size": 300,
15+
"sha1": "000647771481d39dd3a53f6dc210c26abac37748",
16+
"licenses": []
17+
},
18+
{
19+
"path": "some/path/b/b1.py",
20+
"type": "file",
21+
"name": "b1.py",
22+
"size": 290,
23+
"sha1": "333647771481d39dd3a53f6dc210c26abac37748",
24+
"licenses": [
25+
{
26+
"key": "mit",
27+
"score": 100.0,
28+
"short_name": "MIT License",
29+
"category": "Permissive"
30+
}
31+
]
32+
}
33+
]
34+
}

0 commit comments

Comments
 (0)