diff --git a/gqrxHandler.py b/gqrxHandler.py index a17f60c..c3afbd1 100644 --- a/gqrxHandler.py +++ b/gqrxHandler.py @@ -1,3 +1,4 @@ +import configparser import shutil import logging import threading @@ -213,19 +214,26 @@ class GQRXHandler(threading.Thread): self.change_freq(_freq) self.change_squelch(_squelch) + def creat_config(self): + from templates.gqrx_config_template import drb_defaults + config = drb_defaults + try: + with open(self.GQRX_Config_Path, 'w+') as config_file: + config_file.write(config) + except OSError as err: + self.logger.error(err) + def reset_or_create_config(self): if self.GQRX_Config_Path.is_file(): - self.logger.debug(f"Enabling AGC in the GQRX config") - enable_agc(_config_path=self.GQRX_Config_Path) + try: + self.logger.debug(f"Enabling AGC in the GQRX config") + enable_agc(_config_path=self.GQRX_Config_Path) - self.logger.debug(f"GQRX Config exists, resetting 'crashed' setting") - reset_crashed(_config_path=self.GQRX_Config_Path) + self.logger.debug(f"GQRX Config exists, resetting 'crashed' setting") + reset_crashed(_config_path=self.GQRX_Config_Path) + except configparser.DuplicateOptionError as err: + self.logger.warning(err) + self.creat_config() else: self.logger.debug(f"GQRX config does not exist, creating it from template") - from templates.gqrx_config_template import drb_defaults - config = drb_defaults - try: - with open(self.GQRX_Config_Path, 'w+') as config_file: - config_file.write(config) - except OSError as err: - self.logger.error(err) + self.creat_config()