Compute tallies of a scan at the codebase level for available scans. If `keep_details` is True, also keep file and directory details in the `tallies` file attribute for every file and directory.
(codebase, keep_details, **kwargs)
| 107 | |
| 108 | |
| 109 | def compute_codebase_tallies(codebase, keep_details, **kwargs): |
| 110 | """ |
| 111 | Compute tallies of a scan at the codebase level for available scans. |
| 112 | |
| 113 | If `keep_details` is True, also keep file and directory details in the |
| 114 | `tallies` file attribute for every file and directory. |
| 115 | """ |
| 116 | from summarycode.copyright_tallies import (author_tallies, |
| 117 | copyright_tallies, |
| 118 | holder_tallies) |
| 119 | |
| 120 | attrib_summarizers = [ |
| 121 | ('detected_license_expression', license_tallies), |
| 122 | ('copyrights', copyright_tallies), |
| 123 | ('holders', holder_tallies), |
| 124 | ('authors', author_tallies), |
| 125 | ('programming_language', language_tallies), |
| 126 | ('packages', package_tallies), |
| 127 | ] |
| 128 | |
| 129 | # find which attributes are available for summarization by checking the root |
| 130 | # resource |
| 131 | root = codebase.root |
| 132 | summarizers = [s for a, s in attrib_summarizers if hasattr(root, a)] |
| 133 | if TRACE: logger_debug('compute_codebase_tallies with:', summarizers) |
| 134 | |
| 135 | # collect and set resource-level summaries |
| 136 | for resource in codebase.walk(topdown=False): |
| 137 | children = resource.children(codebase) |
| 138 | |
| 139 | for summarizer in summarizers: |
| 140 | _summary_data = summarizer(resource, children, keep_details=keep_details) |
| 141 | if TRACE: logger_debug('tallies for:', resource.path, 'after tallies:', summarizer, 'is:', _summary_data) |
| 142 | |
| 143 | codebase.save_resource(resource) |
| 144 | |
| 145 | # set the tallies from the root resource at the codebase level |
| 146 | if keep_details: |
| 147 | tallies = root.tallies |
| 148 | else: |
| 149 | tallies = root.extra_data.get('tallies', {}) |
| 150 | |
| 151 | if TRACE: logger_debug('codebase tallies:', tallies) |
| 152 | return tallies |
| 153 | |
| 154 | |
| 155 | def license_tallies(resource, children, keep_details=False): |
no test coverage detected