|
33 | 33 | from commoncode import paths |
34 | 34 |
|
35 | 35 |
|
36 | | -def determine_license_diff(delta, unique_categories): |
| 36 | +def update_from_license_info(delta, unique_categories): |
37 | 37 | """ |
38 | | - Increase the Delta object's 'score' attribute and add one or more |
39 | | - appropriate categories to its 'factors' attribute if there has been a |
40 | | - license change and depending on the nature of that change. |
| 38 | + Increase an 'added' or 'modified' Delta object's 'score' attribute and add |
| 39 | + one or more appropriate categories to its 'factors' attribute if there has |
| 40 | + been a license change and depending on the nature of that change. |
41 | 41 | """ |
42 | | - if not delta.is_modified(): |
| 42 | + if delta.is_added(): |
| 43 | + update_added_from_license_info(delta, unique_categories) |
| 44 | + |
| 45 | + if delta.is_modified(): |
| 46 | + update_modified_from_license_info(delta, unique_categories) |
| 47 | + |
| 48 | + |
| 49 | +def update_added_from_license_info(delta, unique_categories): |
| 50 | + """ |
| 51 | + Increase an 'added' Delta object's 'score' attribute and add |
| 52 | + one or more categories to its 'factors' attribute if there has |
| 53 | + been a license change. |
| 54 | + """ |
| 55 | + new_licenses = delta.new_file.licenses or [] |
| 56 | + new_categories = set(license.category for license in new_licenses) |
| 57 | + |
| 58 | + if delta.new_file.has_licenses(): |
| 59 | + delta.update(20, 'license info added') |
| 60 | + # no license ==> 'Copyleft Limited'or higher |
| 61 | + for category in new_categories: |
| 62 | + if category in unique_categories: |
| 63 | + delta.update(20, category.lower() + ' added') |
43 | 64 | return |
44 | 65 |
|
| 66 | + |
| 67 | +def update_modified_from_license_info(delta, unique_categories): |
| 68 | + """ |
| 69 | + Increase a 'modified' Delta object's 'score' attribute and add |
| 70 | + one or more categories to its 'factors' attribute if there has |
| 71 | + been a license change. |
| 72 | + """ |
45 | 73 | if not delta.new_file.has_licenses() and delta.old_file.has_licenses(): |
46 | 74 | delta.update(15, 'license info removed') |
47 | 75 | return |
@@ -71,15 +99,36 @@ def determine_license_diff(delta, unique_categories): |
71 | 99 | delta.update(20, category.lower() + ' added') |
72 | 100 |
|
73 | 101 |
|
74 | | -def determine_copyright_diff(delta): |
| 102 | +def update_from_copyright_info(delta): |
| 103 | + """ |
| 104 | + Increase an 'added' or 'modified' Delta object's 'score' attribute and add |
| 105 | + one or more appropriate categories to its 'factors' attribute if there has |
| 106 | + been a copyright change and depending on the nature of that change. |
| 107 | + """ |
| 108 | + if delta.is_added(): |
| 109 | + update_added_from_copyright_info(delta) |
| 110 | + |
| 111 | + if delta.is_modified(): |
| 112 | + update_modified_from_copyright_info(delta) |
| 113 | + |
| 114 | + |
| 115 | +def update_added_from_copyright_info(delta): |
75 | 116 | """ |
76 | | - Increase the Delta object's 'score' attribute and add one or more |
77 | | - appropriate categories to its 'factors' attribute if there has been a |
78 | | - copyright change and depending on the nature of that change. |
| 117 | + Increase an 'added' Delta object's 'score' attribute and add |
| 118 | + one or more categories to its 'factors' attribute if there has |
| 119 | + been a copyright change. |
79 | 120 | """ |
80 | | - if not delta.is_modified(): |
| 121 | + if delta.new_file.has_copyrights(): |
| 122 | + delta.update(10, 'copyright info added') |
81 | 123 | return |
82 | 124 |
|
| 125 | + |
| 126 | +def update_modified_from_copyright_info(delta): |
| 127 | + """ |
| 128 | + Increase a 'modified' Delta object's 'score' attribute and add |
| 129 | + one or more categories to its 'factors' attribute if there has |
| 130 | + been a copyright change. |
| 131 | + """ |
83 | 132 | new_copyrights = delta.new_file.copyrights or [] |
84 | 133 | old_copyrights = delta.old_file.copyrights or [] |
85 | 134 |
|
|
0 commit comments