Total Complexity | 10 |
Total Lines | 61 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | #!/usr/bin/env python3 |
||
2 | |||
3 | # -*- coding: utf-8 -*- |
||
4 | |||
5 | import importlib |
||
6 | import inspect |
||
7 | import sys |
||
8 | |||
9 | # mixin for ansible.plugins.filters.* |
||
10 | |||
11 | class FilterModule(object): |
||
12 | |||
13 | def __init__(self): |
||
14 | self._filters = {} |
||
15 | |||
16 | def filters(self): |
||
17 | |||
18 | for spec in [ |
||
19 | 'ansible.plugins.filter.core', |
||
20 | 'ansible.plugins.filter.mathstuff', |
||
21 | 'ansible.plugins.filter.urls', |
||
22 | 'ansible.plugins.filter.urlsplit', |
||
23 | ]: |
||
24 | |||
25 | mod = importlib.import_module(spec) |
||
26 | |||
27 | if hasattr(mod, 'FilterModule'): |
||
28 | _filters = mod.FilterModule().filters() |
||
29 | for k,v in _filters.items(): |
||
30 | self._filters.update( { |
||
31 | k: [ "{}.{}".format(spec, k), v ] |
||
32 | } ) |
||
33 | |||
34 | del mod |
||
35 | return self._filters |
||
36 | |||
37 | class TestModule(object): |
||
38 | |||
39 | def __init__(self): |
||
40 | self._tests = {} |
||
41 | |||
42 | def tests(self): |
||
43 | |||
44 | for spec in [ |
||
45 | 'ansible.plugins.test.core', |
||
46 | 'ansible.plugins.test.files', |
||
47 | 'ansible.plugins.test.mathstuff', |
||
48 | ]: |
||
49 | |||
50 | mod = importlib.import_module(spec) |
||
51 | |||
52 | if hasattr(mod, 'TestModule'): |
||
53 | _tests = mod.TestModule().tests() |
||
54 | for k,v in _tests.items(): |
||
55 | self._tests.update( { |
||
56 | k: [ "{}.{}".format(spec, k), v ] |
||
57 | } ) |
||
58 | |||
59 | del mod |
||
60 | return self._tests |
||
61 |