Set a variable into the configuration object. Note: Since we use the ConfigParser class, the section names are case-sensitive but the keys are not. Args: key: The key of the variable to be set. value: The value of the variable to be set.
(self, key: str, value: Any, section: str | None = None)
| 49 | """ |
| 50 | |
| 51 | def set_variable(self, key: str, value: Any, section: str | None = None): |
| 52 | """Set a variable into the configuration object. |
| 53 | |
| 54 | Note: |
| 55 | Since we use the ConfigParser class, the section names are case-sensitive but the keys are not. |
| 56 | |
| 57 | Args: |
| 58 | key: The key of the variable to be set. |
| 59 | value: The value of the variable to be set. |
| 60 | section: The section of the configuration object to set the variable in. |
| 61 | Defaults to None, in which case the default section is used. |
| 62 | |
| 63 | Raises: |
| 64 | configparser.Error: If no section is specified and the default section is None. |
| 65 | """ |
| 66 | # resolve the section |
| 67 | if section is None: |
| 68 | if self.namespace is None: |
| 69 | raise configparser.Error("No section specified. Please specify a section or set StateFile.namespace.") |
| 70 | section = self.namespace |
| 71 | |
| 72 | # create section if it does not exist |
| 73 | if section not in self.loaded_cfg.sections(): |
| 74 | self.loaded_cfg.add_section(section) |
| 75 | # set the variable |
| 76 | self.loaded_cfg.set(section, key, value) |
| 77 | |
| 78 | def get_variable(self, key: str, section: str | None = None) -> Any: |
| 79 | """Get a variable from the configuration object. |
no outgoing calls
no test coverage detected