Delete a variable from 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 deleted. section: The section of the configuration obj
(self, key: str, section: str | None = None)
| 101 | return self.loaded_cfg.get(section, key, fallback=None) |
| 102 | |
| 103 | def delete_variable(self, key: str, section: str | None = None): |
| 104 | """Delete a variable from the configuration object. |
| 105 | |
| 106 | Note: |
| 107 | Since we use the ConfigParser class, the section names are case-sensitive but the keys are not. |
| 108 | |
| 109 | Args: |
| 110 | key: The key of the variable to be deleted. |
| 111 | section: The section of the configuration object to remove the variable from. |
| 112 | Defaults to None, in which case the default section is used. |
| 113 | |
| 114 | Raises: |
| 115 | configparser.Error: If no section is specified and the default section is None. |
| 116 | configparser.NoSectionError: If the section does not exist in the configuration object. |
| 117 | configparser.NoOptionError: If the key does not exist in the section. |
| 118 | """ |
| 119 | # resolve the section |
| 120 | if section is None: |
| 121 | if self.namespace is None: |
| 122 | raise configparser.Error("No section specified. Please specify a section or set StateFile.namespace.") |
| 123 | section = self.namespace |
| 124 | |
| 125 | # check if the section exists |
| 126 | if section not in self.loaded_cfg.sections(): |
| 127 | raise configparser.NoSectionError(f"Section '{section}' does not exist in the file: {self.path}") |
| 128 | |
| 129 | # check if the key exists |
| 130 | if self.loaded_cfg.has_option(section, key): |
| 131 | self.loaded_cfg.remove_option(section, key) |
| 132 | else: |
| 133 | raise configparser.NoOptionError(option=key, section=section) |
| 134 | |
| 135 | """ |
| 136 | Operations - File I/O. |