diff --git a/src/deltacode/__init__.py b/src/deltacode/__init__.py index 2500b373..1bbf3843 100644 --- a/src/deltacode/__init__.py +++ b/src/deltacode/__init__.py @@ -133,7 +133,7 @@ def create_deltas( def determine_delta(self): """ Create Delta objects and append them to the list. Top Down BFS Traversal is used - to visit the codebase structures of the old and new Codebase Directiries. + to visit the codebase structures of the old and new Codebase Directories. """ old_resource_considered = set() @@ -271,8 +271,14 @@ def license_diff(self): ] ) + license_refs = {} + for license_reference in self.codebase1.attributes.license_references: + license_refs[license_reference["key"]] = license_reference["category"] + for license_reference in self.codebase2.attributes.license_references: + license_refs[license_reference["key"]] = license_reference["category"] + for delta in self.deltas: - utils.update_from_license_info(delta, unique_categories) + utils.update_from_license_info(delta, unique_categories, license_refs) def copyright_diff(self): """ @@ -380,15 +386,13 @@ def licenses_to_dict(self, file): """ licenses = [] try: - for license in file.licenses: + for license in file.license_detections: licenses.append( OrderedDict( [ - ("key", license.get("key", None)), - ("score", license.get("score", None)), - ("short_name", license.get("short_name", None)), - ("category", license.get("category", None)), - ("owner", license.get("owner", None)), + ("identifier", license.get("identifier", None)), + ("license_expression", license.get("license_expression", None)), + ("matches", license.get("matches", None)), ] ) ) diff --git a/src/deltacode/cli.py b/src/deltacode/cli.py index 79d7bdc5..a9d8eb73 100644 --- a/src/deltacode/cli.py +++ b/src/deltacode/cli.py @@ -92,3 +92,6 @@ def cli(new, old, json_file, all_delta_types): deltacode = DeltaCode(new, old, options) # generate JSON output write_json(deltacode, json_file, all_delta_types) + +if __name__ == "__main__": + cli() \ No newline at end of file diff --git a/src/deltacode/models.py b/src/deltacode/models.py index ed7bee88..df23a490 100644 --- a/src/deltacode/models.py +++ b/src/deltacode/models.py @@ -248,10 +248,36 @@ class License(object): """ def __init__(self, dictionary={}): self.key = dictionary.get('key') - self.score = dictionary.get('score') + self.language = dictionary.get('language') self.short_name = dictionary.get('short_name') + self.name = dictionary.get('name') self.category = dictionary.get('category') self.owner = dictionary.get('owner') + self.homepage_url = dictionary.get('homepage_url') + self.notes = dictionary.get('notes') + self.is_builtin = dictionary.get('is_builtin') + self.is_exception = dictionary.get('is_exception') + self.is_unknown = dictionary.get('is_unknown') + self.is_generic = dictionary.get('is_generic') + self.spdx_license_key = dictionary.get('spdx_license_key') + self.other_spdx_license_keys = dictionary.get('other_spdx_license_keys') + self.osi_license_key = dictionary.get('osi_license_key') + self.text_urls = dictionary.get('text_urls') + self.osi_url = dictionary.get('osi_url') + self.faq_url = dictionary.get('faq_url') + self.other_urls = dictionary.get('other_urls') + self.key_aliases = dictionary.get('key_aliases') + self.minimum_coverage = dictionary.get('minimum_coverage') + self.standard_notice = dictionary.get('standard_notice') + self.ignorable_copyrights = dictionary.get('ignorable_copyrights') + self.ignorable_holders = dictionary.get('ignorable_holders') + self.ignorable_authors = dictionary.get('ignorable_authors') + self.ignorable_urls = dictionary.get('ignorable_urls') + self.ignorable_emails = dictionary.get('ignorable_emails') + self.text = dictionary.get('text') + self.scancode_url = dictionary.get('scancode_url') + self.licensedb_url = dictionary.get('licensedb_url') + self.spdx_url = dictionary.get('spdx_url') def to_dict(self): """ @@ -260,10 +286,36 @@ def to_dict(self): """ d = OrderedDict([ ('key', self.key), - ('score', self.score), + ('language', self.language), ('short_name', self.short_name), + ('name', self.name), ('category', self.category), - ('owner', self.owner) + ('owner', self.owner), + ('homepage_url', self.homepage_url), + ('notes', self.notes), + ('is_builtin', self.is_builtin), + ('is_exception', self.is_exception), + ('is_unknown', self.is_unknown), + ('is_generic', self.is_generic), + ('spdx_license_key', self.spdx_license_key), + ('other_spdx_license_keys', self.other_spdx_license_keys), + ('osi_license_key', self.osi_license_key), + ('text_urls', self.text_urls), + ('osi_url', self.osi_url), + ('faq_url', self.faq_url), + ('other_urls', self.other_urls), + ('key_aliases', self.key_aliases), + ('minimum_coverage', self.minimum_coverage), + ('standard_notice', self.standard_notice), + ('ignorable_copyrights', self.ignorable_copyrights), + ('ignorable_holders', self.ignorable_holders), + ('ignorable_authors', self.ignorable_authors), + ('ignorable_urls', self.ignorable_urls), + ('ignorable_emails', self.ignorable_emails), + ('text', self.text), + ('scancode_url', self.scancode_url), + ('licensedb_url', self.licensedb_url), + ('spdx_url', self.spdx_url) ]) return d diff --git a/src/deltacode/utils.py b/src/deltacode/utils.py index 0fceb5ee..10734b94 100644 --- a/src/deltacode/utils.py +++ b/src/deltacode/utils.py @@ -36,31 +36,33 @@ from collections import OrderedDict -def update_from_license_info(delta, unique_categories): +def update_from_license_info(delta, unique_categories, license_refs): """ 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. """ if delta.is_added(): - update_added_from_license_info(delta, unique_categories) + update_added_from_license_info(delta, unique_categories, license_refs) if delta.is_modified(): - update_modified_from_license_info(delta, unique_categories) + update_modified_from_license_info(delta, unique_categories, license_refs) -def update_added_from_license_info(delta, unique_categories): +def update_added_from_license_info(delta, unique_categories, license_refs): """ 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. """ new_licenses = ( - delta.new_file.licenses if hasattr(delta.new_file, "licenses") else [] + delta.new_file.license_detections if hasattr(delta.new_file, "license_detections") else [] ) - new_categories = set(license["category"] for license in new_licenses) - if hasattr(delta.new_file, "licenses"): + new_categories = set() + for license in new_licenses: + new_categories.add(license_refs.get(license["license_expression"], "N/A")) + if hasattr(delta.new_file, "license_detections"): delta.update(20, "license info added") for category in new_categories: # no license ==> 'Copyleft Limited'or higher @@ -72,7 +74,7 @@ def update_added_from_license_info(delta, unique_categories): return -def update_modified_from_license_info(delta, unique_categories): +def update_modified_from_license_info(delta, unique_categories, license_refs): """ Increase a 'modified' Delta object's 'score' attribute and add one or more categories to its 'factors' attribute if there has @@ -80,18 +82,22 @@ def update_modified_from_license_info(delta, unique_categories): """ new_licenses = ( - delta.new_file.licenses if hasattr(delta.new_file, "licenses") else [] + delta.new_file.license_detections if hasattr(delta.new_file, "license_detections") else [] ) old_licenses = ( - delta.old_file.licenses if hasattr(delta.old_file, "licenses") else [] + delta.old_file.license_detections if hasattr(delta.old_file, "license_detections") else [] ) if not new_licenses and old_licenses: delta.update(15, "license info removed") return - new_categories = set(license.get("category", "") for license in new_licenses) - old_categories = set(license.get("category", "") for license in old_licenses) + new_categories = set() + for license in new_licenses: + new_categories.add(license_refs.get(license["license_expression"], "N/A")) + old_categories = set() + for license in old_licenses: + old_categories.add(license_refs.get(license["license_expression"], "N/A")) if new_licenses and not old_licenses: delta.update(20, "license info added") @@ -105,11 +111,10 @@ def update_modified_from_license_info(delta, unique_categories): delta.update(0, category.lower() + " added") return - new_keys = set(license.get("key", "") for license in new_licenses) - old_keys = set(license.get("key", "") for license in old_licenses) - - if new_keys != old_keys: + new_ids = set(license.get("identifier", "") for license in new_licenses) + old_ids = set(license.get("identifier", "") for license in old_licenses) + if new_ids != old_ids: delta.update(10, "license change") for category in new_categories - old_categories: unique_categories_in_old_file = len(old_categories & unique_categories)