Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Score,Factors,Path,Name,Type,Size,Old Path
70,modified license info added copyleft added copyright info added,path.txt,path.txt,file,300,
70,modified license info added copyright info added,path.txt,path.txt,file,300,
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"deltacode_notice": "Generated with DeltaCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nDeltaCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nDeltaCode is a free software codebase-comparison tool from nexB Inc. and others.\nVisit https://github.com/nexB/deltacode/ for support and download.",
"deltacode_options": {
"new_scan_path": "C:/code/nexb/dev/deltacode/tests/data/cli/copyright_and_license_info_added_new.json",
"old_scan_path": "C:/code/nexb/dev/deltacode/tests/data/cli/copyright_and_license_info_added_old.json",
"--new": "C:/code/nexb/dev/deltacode/tests/data/cli/copyright_and_license_info_added_new.json",
"--old": "C:/code/nexb/dev/deltacode/tests/data/cli/copyright_and_license_info_added_old.json",
"--all-delta-types": false
},
"deltacode_version": "1.0.0.post37.cba847f.dirty.20180402221516",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
Score,Factors,Path,Name,Type,Size,Old Path
70,modified license info added copyleft added copyright info removed,path.txt,path.txt,file,300,
70,modified license info added copyright info removed,path.txt,path.txt,file,300,
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"deltacode_notice": "Generated with DeltaCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nDeltaCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nDeltaCode is a free software codebase-comparison tool from nexB Inc. and others.\nVisit https://github.com/nexB/deltacode/ for support and download.",
"deltacode_options": {
"new_scan_path": "C:/code/nexb/dev/deltacode/tests/data/cli/license_info_added_copyright_info_removed_new.json",
"old_scan_path": "C:/code/nexb/dev/deltacode/tests/data/cli/license_info_added_copyright_info_removed_old.json",
"--new": "C:/code/nexb/dev/deltacode/tests/data/cli/license_info_added_copyright_info_removed_new.json",
"--old": "C:/code/nexb/dev/deltacode/tests/data/cli/license_info_added_copyright_info_removed_old.json",
"--all-delta-types": false
},
"deltacode_version": "1.0.0.post37.cba847f.dirty.20180402221516",
Expand Down
2 changes: 1 addition & 1 deletion etc/scripts/testdata/json2csv/new_license_added.csv
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
Score,Factors,Path,Name,Type,Size,Old Path
50,modified license change,some/path/a/a1.py,a1.py,file,300,
20,modified,some/path/c/c1.py,c1.py,file,300,
30,modified license change,some/path/b/b1.py,b1.py,file,300,
50,modified license change copyleft added,some/path/a/a1.py,a1.py,file,300,
113 changes: 56 additions & 57 deletions etc/scripts/testdata/json2csv/new_license_added.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,48 @@
{
"deltacode_notice": "Generated with DeltaCode and provided on an \"AS IS\" BASIS, WITHOUT WARRANTIES\nOR CONDITIONS OF ANY KIND, either express or implied. No content created from\nDeltaCode should be considered or used as legal advice. Consult an Attorney\nfor any legal advice.\nDeltaCode is a free software codebase-comparison tool from nexB Inc. and others.\nVisit https://github.com/nexB/deltacode/ for support and download.",
"deltacode_options": {
"new_scan_path": "C:/code/nexb/dev/deltacode/tests/data/cli/scan_modified_new_license_added.json",
"old_scan_path": "C:/code/nexb/dev/deltacode/tests/data/cli/scan_modified_old_license_added.json",
"--new": "C:/code/nexb/dev/deltacode/tests/data/cli/scan_modified_new_license_added.json",
"--old": "C:/code/nexb/dev/deltacode/tests/data/cli/scan_modified_old_license_added.json",
"--all-delta-types": false
},
"deltacode_version": "1.0.0.post37.cba847f.dirty.20180402221516",
"deltacode_errors": [],
"deltas": [
{
"factors": [
"modified"
"modified",
"license change"
],
"score": 20,
"score": 50,
"new": {
"path": "some/path/c/c1.py",
"path": "some/path/a/a1.py",
"type": "file",
"name": "c1.py",
"name": "a1.py",
"size": 300,
"sha1": "333647771481d39dd3a53f6dc210c26abac37748",
"original_path": "some/path/c/c1.py",
"original_path": "some/path/a/a1.py",
"licenses": [
{
"key": "apache-2.0",
"score": 80.0,
"short_name": "Apache 2.0",
"category": "Permissive",
"owner": null
},
{
"key": "agpl-2.0",
"score": 70.0,
"short_name": "AGPL 2.0",
"category": "Copyleft",
"owner": null
},
{
"key": "bsd-simplified",
"score": 100.0,
"short_name": "BSD-Simplified",
"category": "Permissive",
"owner": null
},
{
"key": "mit",
"score": 100.0,
Expand All @@ -32,17 +54,30 @@
"copyrights": []
},
"old": {
"path": "some/path/c/c1.py",
"path": "some/path/a/a1.py",
"type": "file",
"name": "c1.py",
"name": "a1.py",
"size": 300,
"sha1": "222647771481d39dd3a53f6dc210c26abac37748",
"original_path": "some/path/c/c1.py",
"original_path": "some/path/a/a1.py",
"licenses": [
{"key": "apache-2.0",
"score": 80.0,
"short_name": "Apache 2.0",
"category": "Permissive",
"owner": null
},
{
"key": "mit",
"key": "public-domain",
"score": 10.0,
"short_name": "Public Domain",
"category": "Public Domain",
"owner": null
},
{
"key": "bsd-simplified",
"score": 100.0,
"short_name": "MIT License",
"short_name": "BSD-Simplified",
"category": "Permissive",
"owner": null
}
Expand All @@ -52,8 +87,7 @@
},
{
"factors": [
"modified",
"license change"
"modified"
],
"score": 30,
"new": {
Expand All @@ -64,27 +98,6 @@
"sha1": "111647771481d39dd3a53f6dc210c26abac37748",
"original_path": "some/path/b/b1.py",
"licenses": [
{
"key": "apache-2.0",
"score": 80.0,
"short_name": "Apache 2.0",
"category": "Permissive",
"owner": null
},
{
"key": "gpl-2.0",
"score": 60.0,
"short_name": "GPL 2.0",
"category": "Copyleft",
"owner": null
},
{
"key": "bsd-simplified",
"score": 100.0,
"short_name": "BSD-Simplified",
"category": "Permissive",
"owner": null
},
{
"key": "mit",
"score": 100.0,
Expand All @@ -104,23 +117,9 @@
"original_path": "some/path/b/b1.py",
"licenses": [
{
"key": "mpl-2.0",
"score": 90.0,
"short_name": "MPL 2.0",
"category": "Copyleft Limited",
"owner": null
},
{
"key": "public-domain",
"score": 10.0,
"short_name": "Public Domain",
"category": "Public Domain",
"owner": null
},
{
"key": "bsd-simplified",
"key": "mit",
"score": 100.0,
"short_name": "BSD-Simplified",
"short_name": "MIT-License",
"category": "Permissive",
"owner": null
}
Expand All @@ -136,12 +135,12 @@
],
"score": 50,
"new": {
"path": "some/path/a/a1.py",
"path": "some/path/c/c1.py",
"type": "file",
"name": "a1.py",
"name": "c1.py",
"size": 300,
"sha1": "000647771481d39dd3a53f6dc210c26abac37748",
"original_path": "some/path/a/a1.py",
"original_path": "some/path/c/c1.py",
"licenses": [
{
"key": "apache-2.0",
Expand Down Expand Up @@ -175,12 +174,12 @@
"copyrights": []
},
"old": {
"path": "some/path/a/a1.py",
"path": "some/path/c/c1.py",
"type": "file",
"name": "a1.py",
"name": "c1.py",
"size": 200,
"sha1": "84b647771481d39dd3a53f6dc210c26abac37748",
"original_path": "some/path/a/a1.py",
"original_path": "some/path/c/c1.py",
"licenses": [
{
"key": "apache-2.0",
Expand Down
87 changes: 44 additions & 43 deletions src/deltacode/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@

def update_from_license_info(delta, unique_categories):
"""
Increase an 'added' or 'modified' Delta object's 'score' attribute and add
one or more appropriate categories to its 'factors' attribute if there has
been a license change and depending on the nature of that change.
Increase an 'added' or 'modified' Delta object's 'score' attribute and
annotate its 'factors' attribute if there has been a license change and
depending on the nature of that change.
"""
if delta.is_added():
update_added_from_license_info(delta, unique_categories)
Expand All @@ -48,70 +48,71 @@ def update_from_license_info(delta, unique_categories):

def update_added_from_license_info(delta, unique_categories):
"""
Increase an 'added' Delta object's 'score' attribute and add
one or more categories to its 'factors' attribute if there has
been a license change.
Increase an 'added' Delta object's 'score' attribute and annotate its
'factors' attribute if there has been a license change.
"""
new_licenses = delta.new_file.licenses or []
new_categories = set(license.category for license in new_licenses)

if delta.new_file.has_licenses():
delta.update(20, 'license info added')

for category in new_categories:
# no license ==> 'Copyleft Limited'or higher
if category in unique_categories:
delta.update(20, category.lower() + ' added')
# no license ==> 'Permissive' or 'Public Domain'
else:
delta.update(0, category.lower() + ' added')
# delta.update(20, 'license info added')
#
# for category in new_categories:
# # no license ==> 'Copyleft Limited'or higher
# if category in unique_categories:
# delta.update(20, category.lower() + ' added')
# # no license ==> 'Permissive' or 'Public Domain'
# else:
# delta.update(0, category.lower() + ' added')
delta.update(score=20, factor='license info added')
return


def update_modified_from_license_info(delta, unique_categories):
"""
Increase a 'modified' Delta object's 'score' attribute and add
one or more categories to its 'factors' attribute if there has
been a license change.
Increase a 'modified' Delta object's 'score' attribute and annotate its
'factors' attribute if there has been a license change.
"""
if not delta.new_file.has_licenses() and delta.old_file.has_licenses():
delta.update(15, 'license info removed')
delta.update(score=15, factor='license info removed')
return

new_licenses = delta.new_file.licenses or []
old_licenses = delta.old_file.licenses or []

new_categories = set(license.category for license in new_licenses)
old_categories = set(license.category for license in old_licenses)
# new_categories = set(license.category for license in new_licenses)
# old_categories = set(license.category for license in old_licenses)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Delete these lines instead of adding comments


if delta.new_file.has_licenses() and not delta.old_file.has_licenses():
delta.update(20, 'license info added')

for category in new_categories:
# no license ==> 'Copyleft Limited'or higher
if category in unique_categories:
delta.update(20, category.lower() + ' added')
# no license ==> 'Permissive' or 'Public Domain'
else:
delta.update(0, category.lower() + ' added')
return
# delta.update(20, 'license info added')
#
# for category in new_categories:
# # no license ==> 'Copyleft Limited'or higher
# if category in unique_categories:
# delta.update(20, category.lower() + ' added')
# # no license ==> 'Permissive' or 'Public Domain'
# else:
# delta.update(0, category.lower() + ' added')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here, see above comments

delta.update(score=20, factor='license info added')
return

new_keys = set(license.key for license in new_licenses)
old_keys = set(license.key for license in old_licenses)

if new_keys != old_keys:
delta.update(10, 'license change')
for category in new_categories - old_categories:
unique_categories_in_old_file = len(old_categories & unique_categories)
# 'Permissive' or 'Public Domain' ==> 'Copyleft Limited' or higher
if unique_categories_in_old_file == 0 and category in unique_categories:
delta.update(20, category.lower() + ' added')
# at least 1 category in the old file was 'Copyleft Limited' or higher ==> 'Copyleft Limited' or higher
elif unique_categories_in_old_file != 0 and category in unique_categories:
delta.update(10, category.lower() + ' added')
# 'Permissive' or 'Public Domain' ==> 'Permissive' or 'Public Domain' if not in old_categories
elif category not in unique_categories:
delta.update(0, category.lower() + ' added')
# delta.update(10, 'license change')
# for category in new_categories - old_categories:
# unique_categories_in_old_file = len(old_categories & unique_categories)
# # 'Permissive' or 'Public Domain' ==> 'Copyleft Limited' or higher
# if unique_categories_in_old_file == 0 and category in unique_categories:
# delta.update(20, category.lower() + ' added')
# # at least 1 category in the old file was 'Copyleft Limited' or higher ==> 'Copyleft Limited' or higher
# elif unique_categories_in_old_file != 0 and category in unique_categories:
# delta.update(10, category.lower() + ' added')
# # 'Permissive' or 'Public Domain' ==> 'Permissive' or 'Public Domain' if not in old_categories
# elif category not in unique_categories:
# delta.update(0, category.lower() + ' added')

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above

delta.update(score=10, factor='license change')


def update_from_copyright_info(delta):
Expand Down
Loading