Class responsible for obtaining and parsing content pack configs.
| 25 | |
| 26 | |
| 27 | class ContentPackConfigParser(object): |
| 28 | """ |
| 29 | Class responsible for obtaining and parsing content pack configs. |
| 30 | """ |
| 31 | |
| 32 | GLOBAL_CONFIG_NAME = "config.yaml" |
| 33 | LOCAL_CONFIG_SUFFIX = "_config.yaml" |
| 34 | |
| 35 | def __init__(self, pack_name): |
| 36 | self.pack_name = pack_name |
| 37 | self.pack_path = utils.get_pack_base_path(pack_name=pack_name) |
| 38 | |
| 39 | def get_config(self): |
| 40 | """ |
| 41 | Retrieve config for a particular pack. |
| 42 | |
| 43 | :return: Config object if config is found, ``None`` otherwise. |
| 44 | :rtype: :class:`.ContentPackConfig` or ``None`` |
| 45 | """ |
| 46 | global_config_path = self.get_global_config_path() |
| 47 | config = self.get_and_parse_config(config_path=global_config_path) |
| 48 | |
| 49 | return config |
| 50 | |
| 51 | def get_action_config(self, action_file_path): |
| 52 | """ |
| 53 | Retrieve config for a particular action inside the content pack. |
| 54 | |
| 55 | :param action_file_path: Full absolute path to the action file. |
| 56 | :type action_file_path: ``str`` |
| 57 | |
| 58 | :return: Config object if config is found, ``None`` otherwise. |
| 59 | :rtype: :class:`.ContentPackConfig` or ``None`` |
| 60 | """ |
| 61 | global_config_path = self.get_global_config_path() |
| 62 | config = self.get_and_parse_config(config_path=global_config_path) |
| 63 | |
| 64 | return config |
| 65 | |
| 66 | def get_sensor_config(self, sensor_file_path): |
| 67 | """ |
| 68 | Retrieve config for a particular sensor inside the content pack. |
| 69 | |
| 70 | :param sensor_file_path: Full absolute path to the sensor file. |
| 71 | :type sensor_file_path: ``str`` |
| 72 | |
| 73 | :return: Config object if config is found, ``None`` otherwise. |
| 74 | :rtype: :class:`.ContentPackConfig` or ``None`` |
| 75 | """ |
| 76 | global_config_path = self.get_global_config_path() |
| 77 | config = self.get_and_parse_config(config_path=global_config_path) |
| 78 | |
| 79 | return config |
| 80 | |
| 81 | def get_global_config_path(self): |
| 82 | if not self.pack_path: |
| 83 | return None |
| 84 |
no outgoing calls