From a094ba581d2211b43a5204811e92f7db5a428012 Mon Sep 17 00:00:00 2001 From: Logan Cusano Date: Sun, 10 Apr 2022 13:53:59 -0400 Subject: [PATCH] //WIP v3 GQRX Changes - Better error handling; GQRX config dupes some options for an unknown reason --- gqrxHandler.py | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) 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()