2018-11-14 07:52:36 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
"""Test to verify action plugins have an associated module to provide documentation."""
|
2019-07-12 08:46:20 +02:00
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
2018-11-14 07:52:36 +01:00
|
|
|
|
|
|
|
import os
|
2019-02-05 23:56:04 +01:00
|
|
|
import sys
|
2018-11-14 07:52:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
"""Main entry point."""
|
2019-02-05 23:56:04 +01:00
|
|
|
paths = sys.argv[1:] or sys.stdin.read().splitlines()
|
|
|
|
|
2018-11-14 07:52:36 +01:00
|
|
|
module_names = set()
|
|
|
|
|
2019-08-27 05:40:53 +02:00
|
|
|
module_prefixes = {
|
|
|
|
'lib/ansible/modules/': True,
|
|
|
|
'plugins/modules/': False,
|
|
|
|
}
|
|
|
|
|
|
|
|
action_prefixes = {
|
|
|
|
'lib/ansible/plugins/action/': True,
|
|
|
|
'plugins/action/': False,
|
|
|
|
}
|
|
|
|
|
|
|
|
for path in paths:
|
|
|
|
full_name = get_full_name(path, module_prefixes)
|
|
|
|
|
|
|
|
if full_name:
|
|
|
|
module_names.add(full_name)
|
|
|
|
|
2019-02-05 23:56:04 +01:00
|
|
|
for path in paths:
|
2019-08-27 05:40:53 +02:00
|
|
|
full_name = get_full_name(path, action_prefixes)
|
|
|
|
|
|
|
|
if full_name and full_name not in module_names:
|
|
|
|
print('%s: action plugin has no matching module to provide documentation' % path)
|
|
|
|
|
2019-02-05 23:56:04 +01:00
|
|
|
|
2019-08-27 05:40:53 +02:00
|
|
|
def get_full_name(path, prefixes):
|
|
|
|
"""Return the full name of the plugin at the given path by matching against the given path prefixes, or None if no match is found."""
|
|
|
|
for prefix, flat in prefixes.items():
|
|
|
|
if path.startswith(prefix):
|
|
|
|
relative_path = os.path.relpath(path, prefix)
|
|
|
|
|
|
|
|
if flat:
|
|
|
|
full_name = os.path.basename(relative_path)
|
|
|
|
else:
|
|
|
|
full_name = relative_path
|
|
|
|
|
|
|
|
full_name = os.path.splitext(full_name)[0]
|
|
|
|
|
|
|
|
name = os.path.basename(full_name)
|
|
|
|
|
|
|
|
if name == '__init__':
|
|
|
|
return None
|
2018-11-14 07:52:36 +01:00
|
|
|
|
2019-02-05 23:56:04 +01:00
|
|
|
if name.startswith('_'):
|
|
|
|
name = name[1:]
|
2018-11-14 07:52:36 +01:00
|
|
|
|
2019-08-27 05:40:53 +02:00
|
|
|
full_name = os.path.join(os.path.dirname(full_name), name).replace(os.path.sep, '.')
|
2018-11-14 07:52:36 +01:00
|
|
|
|
2019-08-27 05:40:53 +02:00
|
|
|
return full_name
|
2019-02-05 23:56:04 +01:00
|
|
|
|
2019-08-27 05:40:53 +02:00
|
|
|
return None
|
2018-11-14 07:52:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|