Debian Codegraph @

test/lib/ansible_test/_internal/provider/source/installed.py

raw
1 """Source provider for content which has been installed."""
2
3 from __future__ import annotations
4
5 import os
6
7 from . import (
8 SourceProvider,
9 )
10
11
12 class InstalledSource(SourceProvider):
13 """Source provider for content which has been installed."""
14
15 sequence = 0 # disable automatic detection
16
17 @staticmethod
18 def is_content_root(path: str) -> bool:
19 """Return True if the given path is a content root for this provider."""
20 return False
21
22 def get_paths(self, path: str) -> list[str]:
23 """Return the list of available content paths under the given path."""
24 paths = []
25
26 kill_extensions = (
27 '.pyc',
28 '.pyo',
29 )
30
31 for root, _dummy, file_names in os.walk(path):
32 rel_root = os.path.relpath(root, path)
33
34 if rel_root == '.':
35 rel_root = ''
36
37 paths.extend([os.path.join(rel_root, file_name) for file_name in file_names
38 if not os.path.splitext(file_name)[1] in kill_extensions])
39
40 # NOTE: directory symlinks are ignored as there should be no directory symlinks for an install
41
42 return paths