mirror of
https://github.com/EDCD/EDMarketConnector.git
synced 2025-04-17 17:42:20 +03:00
Ensure that Section exists on linuxconf
When starting EDMC for the first time, linuxconf creates the required file automatically but does _not_ create our config section. This causes a keyerror on any access to config. Simple solution, test that the section exists, if it doesnt, create it (and backup any existing file beforehand)
This commit is contained in:
parent
d475d3194f
commit
985794fbcb
10
config.py
10
config.py
@ -843,6 +843,16 @@ class LinuxConfig(AbstractConfig):
|
||||
logger.debug(f'Error occurred while reading in file. Assuming that we are creating a new one: {e}')
|
||||
self.config.add_section(self.SECTION)
|
||||
|
||||
# Ensure that our section exists
|
||||
try:
|
||||
self.config[self.SECTION].get("this_does_not_exist", fallback=None)
|
||||
except KeyError:
|
||||
logger.info("Config section not found. Backing up existing file (if any) and readding a section header")
|
||||
if self.filename.exists():
|
||||
(self.filename.parent / f'{appname}.ini.backup').write_bytes(self.filename.read_bytes())
|
||||
|
||||
self.config.add_section(self.SECTION)
|
||||
|
||||
if (outdir := self.get_str('outdir')) is None or not pathlib.Path(outdir).is_dir():
|
||||
self.set('outdir', self.home)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user