Return the nth-``levels_up`` ancestor Resource of ``resource`` in ``codebase`` or None. For example, with levels_up=2 and starting with a resource path of `gem-extract/metadata.gz-extract/metadata.gz-extract`, then `gem-extract/` should be returned.
(levels_up, resource, codebase)
| 149 | |
| 150 | |
| 151 | def get_ancestor(levels_up, resource, codebase): |
| 152 | """ |
| 153 | Return the nth-``levels_up`` ancestor Resource of ``resource`` in |
| 154 | ``codebase`` or None. |
| 155 | |
| 156 | For example, with levels_up=2 and starting with a resource path of |
| 157 | `gem-extract/metadata.gz-extract/metadata.gz-extract`, |
| 158 | then `gem-extract/` should be returned. |
| 159 | """ |
| 160 | rounds = 0 |
| 161 | while rounds < levels_up: |
| 162 | resource = resource.parent(codebase) |
| 163 | if not resource: |
| 164 | return |
| 165 | rounds += 1 |
| 166 | return resource |
| 167 | |
| 168 | |
| 169 | def find_root_from_paths(paths, resource, codebase): |