Debian Codegraph @

lib/ansible/galaxy/__init__.py

raw
1 ########################################################################
2 #
3 # (C) 2015, Brian Coca <[email protected]>
4 #
5 # This file is part of Ansible
6 #
7 # Ansible is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
11 #
12 # Ansible is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
16 #
17 # You should have received a copy of the GNU General Public License
18 # along with Ansible. If not, see <http://www.gnu.org/licenses/>.
19 #
20 ########################################################################
21 """ This manages remote shared Ansible objects, mainly roles"""
22
23 from __future__ import annotations
24
25 import os
26
27 import ansible.constants as C
28 from ansible import context
29 from ansible.module_utils.common.text.converters import to_bytes
30 from ansible.module_utils.common.yaml import yaml_load
31
32 # default_readme_template
33 # default_meta_template
34
35
36 def get_collections_galaxy_meta_info():
37 meta_path = os.path.join(os.path.dirname(__file__), 'data', 'collections_galaxy_meta.yml')
38 with open(to_bytes(meta_path, errors='surrogate_or_strict'), 'rb') as galaxy_obj:
39 return yaml_load(galaxy_obj)
40
41
42 class Galaxy(object):
43 """ Keeps global galaxy info """
44
45 def __init__(self):
46 # TODO: eventually remove this as it contains a mismash of properties that aren't really global
47
48 # roles_path needs to be a list and will be by default
49 roles_path = context.CLIARGS.get('roles_path', C.DEFAULT_ROLES_PATH)
50 # cli option handling is responsible for splitting roles_path
51 self.roles_paths = roles_path
52
53 self.roles = {}
54
55 # load data path for resource usage
56 this_dir, this_filename = os.path.split(__file__)
57 type_path = context.CLIARGS.get('role_type', 'default')
58 if type_path == 'default':
59 type_path = os.path.join(type_path, context.CLIARGS.get('type'))
60
61 self.DATA_PATH = os.path.join(this_dir, 'data', type_path)
62
63 @property
64 def default_role_skeleton_path(self):
65 return self.DATA_PATH
66
67 def add_role(self, role):
68 self.roles[role.name] = role
69
70 def remove_role(self, role_name):
71 del self.roles[role_name]