Compute, update and save the counts of every resource. Return a tuple of top level counters for this codebase as: (files_count, dirs_count, size_count). The counts are computed differently based on these flags: - If ``skip_root`` is True, the root resource
(self, skip_root=False, skip_filtered=False)
| 1064 | yield resource |
| 1065 | |
| 1066 | def compute_counts(self, skip_root=False, skip_filtered=False): |
| 1067 | """ |
| 1068 | Compute, update and save the counts of every resource. |
| 1069 | Return a tuple of top level counters for this codebase as: |
| 1070 | (files_count, dirs_count, size_count). |
| 1071 | |
| 1072 | The counts are computed differently based on these flags: |
| 1073 | - If ``skip_root`` is True, the root resource is not included in counts. |
| 1074 | - If ``skip_filtered`` is True, resources with ``is_filtered`` set to True |
| 1075 | are not included in counts. |
| 1076 | """ |
| 1077 | self.update_counts(skip_filtered=skip_filtered) |
| 1078 | |
| 1079 | root = self.root |
| 1080 | files_count = root.files_count |
| 1081 | dirs_count = root.dirs_count |
| 1082 | size_count = root.size_count |
| 1083 | |
| 1084 | if (skip_root and not root.is_file) or (skip_filtered and root.is_filtered): |
| 1085 | return files_count, dirs_count, size_count |
| 1086 | |
| 1087 | if root.is_file: |
| 1088 | files_count += 1 |
| 1089 | else: |
| 1090 | dirs_count += 1 |
| 1091 | size_count += root.size or 0 |
| 1092 | |
| 1093 | return files_count, dirs_count, size_count |
| 1094 | |
| 1095 | def update_counts(self, skip_filtered=False): |
| 1096 | """ |