|
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 | 38 | Increase an 'added' or 'modified' Delta object's 'score' attribute and add |
39 | 39 | one or more appropriate categories to its 'factors' attribute if there has |
40 | 40 | been a license change and depending on the nature of that change. |
41 | 41 | """ |
42 | 42 | if delta.is_added(): |
43 | | - new_licenses = delta.new_file.licenses or [] |
44 | | - new_categories = set(license.category for license in new_licenses) |
45 | | - |
46 | | - if delta.new_file.has_licenses(): |
47 | | - delta.update(20, 'license info added') |
48 | | - # no license ==> 'Copyleft Limited'or higher |
49 | | - for category in new_categories: |
50 | | - if category in unique_categories: |
51 | | - delta.update(20, category.lower() + ' added') |
52 | | - return |
53 | | - |
54 | | - if not delta.is_modified(): |
| 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') |
55 | 64 | return |
56 | 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 | + """ |
57 | 73 | if not delta.new_file.has_licenses() and delta.old_file.has_licenses(): |
58 | 74 | delta.update(15, 'license info removed') |
59 | 75 | return |
@@ -83,20 +99,36 @@ def determine_license_diff(delta, unique_categories): |
83 | 99 | delta.update(20, category.lower() + ' added') |
84 | 100 |
|
85 | 101 |
|
86 | | -def determine_copyright_diff(delta): |
| 102 | +def update_from_copyright_info(delta): |
87 | 103 | """ |
88 | 104 | Increase an 'added' or 'modified' Delta object's 'score' attribute and add |
89 | 105 | one or more appropriate categories to its 'factors' attribute if there has |
90 | 106 | been a copyright change and depending on the nature of that change. |
91 | 107 | """ |
92 | 108 | if delta.is_added(): |
93 | | - if delta.new_file.has_copyrights(): |
94 | | - delta.update(10, 'copyright info added') |
95 | | - return |
| 109 | + update_added_from_copyright_info(delta) |
| 110 | + |
| 111 | + if delta.is_modified(): |
| 112 | + update_modified_from_copyright_info(delta) |
| 113 | + |
96 | 114 |
|
97 | | - if not delta.is_modified(): |
| 115 | +def update_added_from_copyright_info(delta): |
| 116 | + """ |
| 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. |
| 120 | + """ |
| 121 | + if delta.new_file.has_copyrights(): |
| 122 | + delta.update(10, 'copyright info added') |
98 | 123 | return |
99 | 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 | + """ |
100 | 132 | new_copyrights = delta.new_file.copyrights or [] |
101 | 133 | old_copyrights = delta.old_file.copyrights or [] |
102 | 134 |
|
|
0 commit comments