Return a tuple of lists of License objects: - a list of added_to_external - a list of updated_in_external Update the `scancode_licenses` ScanCodeLicenses licenses and texts in-place (e.g. in their current storage directory) from an `external_source` ExternalLicensesSource.
(
scancode_licenses,
external_source,
use_spdx_key=False,
match_text=False,
match_approx=False,
commitish=None,
use_cache=False,
)
| 1077 | |
| 1078 | |
| 1079 | def synchronize_licenses( |
| 1080 | scancode_licenses, |
| 1081 | external_source, |
| 1082 | use_spdx_key=False, |
| 1083 | match_text=False, |
| 1084 | match_approx=False, |
| 1085 | commitish=None, |
| 1086 | use_cache=False, |
| 1087 | ): |
| 1088 | """ |
| 1089 | Return a tuple of lists of License objects: |
| 1090 | - a list of added_to_external |
| 1091 | - a list of updated_in_external |
| 1092 | |
| 1093 | Update the `scancode_licenses` ScanCodeLicenses licenses and texts in-place |
| 1094 | (e.g. in their current storage directory) from an `external_source` |
| 1095 | ExternalLicensesSource. |
| 1096 | |
| 1097 | Also update the external_source licenses this way: |
| 1098 | - original licenses from the external source are left unmodified in the original sub dir |
| 1099 | - new licenses found in scancode that are not in the external source are created in the new sub dir |
| 1100 | - external licenses that are modified from Scancode are created in the updated sub dir |
| 1101 | - external licenses that are not found in Scancode are created in the deleted sub dir |
| 1102 | |
| 1103 | The process is this: |
| 1104 | fetch external remote licenses |
| 1105 | build external license objects in memory, save in the original sub directory |
| 1106 | load scancode licenses |
| 1107 | |
| 1108 | for each scancode license: |
| 1109 | find a possible exact key match with an external license |
| 1110 | if there is a match, update and save the external license object in an "updated" directory |
| 1111 | if there is no match, save the external license object in a "new" directory |
| 1112 | |
| 1113 | for each external license: |
| 1114 | find a possible exact key or spdx key match with a scancode license |
| 1115 | if there is a match, update and save the scancode license object |
| 1116 | if there is no match, create and save a new scancode license object |
| 1117 | |
| 1118 | then later: |
| 1119 | find a possible license text match with a license |
| 1120 | |
| 1121 | """ |
| 1122 | if TRACE: |
| 1123 | print("Synchronize_licenses using SPDX keys:", use_spdx_key) |
| 1124 | |
| 1125 | # mappings of key -> License |
| 1126 | scancodes_by_key = scancode_licenses.by_key |
| 1127 | |
| 1128 | if TRACE_DEEP: |
| 1129 | start = time.time() |
| 1130 | |
| 1131 | externals_by_key = external_source.get_licenses( |
| 1132 | scancode_licenses, |
| 1133 | commitish=commitish, |
| 1134 | use_cache=use_cache, |
| 1135 | ) |
| 1136 |
no test coverage detected