Retrieve content from the provided directories. Provided directories are searched from left to right. If a pack with the same name exists in multiple directories, first pack which is found wins. :param base_dirs: Directories to look into. :type base_dirs: `
(self, base_dirs, content_type)
| 76 | return result |
| 77 | |
| 78 | def get_content(self, base_dirs, content_type): |
| 79 | """ |
| 80 | Retrieve content from the provided directories. |
| 81 | |
| 82 | Provided directories are searched from left to right. If a pack with the same name exists |
| 83 | in multiple directories, first pack which is found wins. |
| 84 | |
| 85 | :param base_dirs: Directories to look into. |
| 86 | :type base_dirs: ``list`` |
| 87 | |
| 88 | :param content_type: Content type to look for (sensors, actions, rules). |
| 89 | :type content_type: ``str`` |
| 90 | |
| 91 | :rtype: ``dict`` |
| 92 | """ |
| 93 | if not isinstance(base_dirs, list): |
| 94 | raise TypeError( |
| 95 | "The base dirs has a value that is not a list" |
| 96 | f" (was {type(base_dirs)})." |
| 97 | ) |
| 98 | |
| 99 | if content_type not in self.ALLOWED_CONTENT_TYPES: |
| 100 | raise ValueError("Unsupported content_type: %s" % (content_type)) |
| 101 | |
| 102 | content = {} |
| 103 | pack_to_dir_map = {} |
| 104 | for base_dir in base_dirs: |
| 105 | if not os.path.isdir(base_dir): |
| 106 | raise ValueError('Directory "%s" doesn\'t exist' % (base_dir)) |
| 107 | |
| 108 | dir_content = self._get_content_from_dir( |
| 109 | base_dir=base_dir, content_type=content_type |
| 110 | ) |
| 111 | |
| 112 | # Check for duplicate packs |
| 113 | for pack_name, pack_content in six.iteritems(dir_content): |
| 114 | if pack_name in content: |
| 115 | pack_dir = pack_to_dir_map[pack_name] |
| 116 | LOG.warning( |
| 117 | 'Pack "%s" already found in "%s", ignoring content from "%s"' |
| 118 | % (pack_name, pack_dir, base_dir) |
| 119 | ) |
| 120 | else: |
| 121 | content[pack_name] = pack_content |
| 122 | pack_to_dir_map[pack_name] = base_dir |
| 123 | |
| 124 | return content |
| 125 | |
| 126 | def get_content_from_pack(self, pack_dir, content_type): |
| 127 | """ |