2019-07-23 04:24:48 +02:00
|
|
|
"""Layout provider for Ansible collections."""
|
|
|
|
from __future__ import (absolute_import, division, print_function)
|
|
|
|
__metaclass__ = type
|
|
|
|
|
|
|
|
import os
|
|
|
|
|
2019-08-06 23:43:29 +02:00
|
|
|
from ... import types as t
|
2019-07-23 04:24:48 +02:00
|
|
|
|
|
|
|
from . import (
|
|
|
|
ContentLayout,
|
|
|
|
LayoutProvider,
|
|
|
|
CollectionDetail,
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
|
|
class CollectionLayout(LayoutProvider):
|
|
|
|
"""Layout provider for Ansible collections."""
|
|
|
|
__module_path = 'plugins/modules'
|
|
|
|
__unit_path = 'test/unit'
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def is_content_root(path): # type: (str) -> bool
|
|
|
|
"""Return True if the given path is a content root for this provider."""
|
|
|
|
if os.path.basename(os.path.dirname(os.path.dirname(path))) == 'ansible_collections':
|
|
|
|
return True
|
|
|
|
|
|
|
|
return False
|
|
|
|
|
|
|
|
def create(self, root, paths): # type: (str, t.List[str]) -> ContentLayout
|
|
|
|
"""Create a Layout using the given root and paths."""
|
2019-08-07 00:13:02 +02:00
|
|
|
plugin_paths = dict((p, os.path.join('plugins', p)) for p in self.PLUGIN_TYPES)
|
2019-07-23 04:24:48 +02:00
|
|
|
|
|
|
|
collection_root = os.path.dirname(os.path.dirname(root))
|
|
|
|
collection_dir = os.path.relpath(root, collection_root)
|
|
|
|
collection_namespace, collection_name = collection_dir.split(os.sep)
|
|
|
|
|
|
|
|
collection_prefix = '%s.%s.' % (collection_namespace, collection_name)
|
|
|
|
collection_root = os.path.dirname(collection_root)
|
|
|
|
|
|
|
|
return ContentLayout(root,
|
|
|
|
paths,
|
|
|
|
plugin_paths=plugin_paths,
|
|
|
|
collection=CollectionDetail(
|
|
|
|
name=collection_name,
|
|
|
|
namespace=collection_namespace,
|
|
|
|
root=collection_root,
|
|
|
|
prefix=collection_prefix,
|
|
|
|
),
|
|
|
|
unit_path='test/unit',
|
2019-07-31 08:29:28 +02:00
|
|
|
unit_module_path='test/unit/plugins/modules',
|
|
|
|
unit_module_utils_path='test/unit/plugins/module_utils',
|
2019-07-23 04:24:48 +02:00
|
|
|
)
|