Update the ``resource`` Resource with a tally of scan fields from itself and its ``children``. Resources and this for the `attributes_list` values list key (such as copyrights, etc) and the ``attribute_value`` details key (such as copyright). - `attributes_list` is the name o
(
resource,
children,
attributes_list,
attribute_value,
tallier,
keep_details=False,
)
| 80 | |
| 81 | |
| 82 | def build_tallies( |
| 83 | resource, |
| 84 | children, |
| 85 | attributes_list, |
| 86 | attribute_value, |
| 87 | tallier, |
| 88 | keep_details=False, |
| 89 | ): |
| 90 | """ |
| 91 | Update the ``resource`` Resource with a tally of scan fields from itself and its |
| 92 | ``children``. |
| 93 | |
| 94 | Resources and this for the `attributes_list` values list key (such as |
| 95 | copyrights, etc) and the ``attribute_value`` details key (such as copyright). |
| 96 | |
| 97 | - `attributes_list` is the name of the attribute values list |
| 98 | ('copyrights', 'holders' etc.) |
| 99 | |
| 100 | - `attribute_value` is the name of the attribute value key in this list |
| 101 | ('copyright', 'holder' etc.) |
| 102 | |
| 103 | - `tallier` is a function that takes a list of texts and returns |
| 104 | texts with counts |
| 105 | """ |
| 106 | # Collect current data |
| 107 | values = getattr(resource, attributes_list, []) |
| 108 | |
| 109 | no_detection_counter = 0 |
| 110 | |
| 111 | if values: |
| 112 | # keep current data as plain strings |
| 113 | candidate_texts = [entry.get(attribute_value) for entry in values] |
| 114 | else: |
| 115 | candidate_texts = [] |
| 116 | if resource.is_file: |
| 117 | no_detection_counter += 1 |
| 118 | |
| 119 | # Collect direct children existing summaries |
| 120 | for child in children: |
| 121 | child_summaries = get_resource_tallies( |
| 122 | child, |
| 123 | key=attributes_list, |
| 124 | as_attribute=keep_details |
| 125 | ) or [] |
| 126 | |
| 127 | for child_summary in child_summaries: |
| 128 | count = child_summary['count'] |
| 129 | value = child_summary['value'] |
| 130 | if value: |
| 131 | candidate_texts.append(Text(value, value, count)) |
| 132 | else: |
| 133 | no_detection_counter += count |
| 134 | |
| 135 | # summarize proper using the provided function |
| 136 | tallied = tallier(candidate_texts) |
| 137 | |
| 138 | # add back the counter of things without detection |
| 139 | if no_detection_counter: |
no test coverage detected