Ensure configuration directory exists before copying config file

This commit is contained in:
2025-10-09 00:01:13 +01:00
parent c151bb796d
commit 766ce8542d
+8 -2
View File
@@ -6,8 +6,11 @@ import shutil
class MonitorSetup(): class MonitorSetup():
def __init__(self): def __init__(self):
self._stg_conf_file = "monitor.conf" self._stg_conf_file = "monitor.conf"
self._conf_file_path = os.path.join(os.path.expanduser('~'), self._conf_file_dir = os.path.join(os.path.expanduser('~'),
".config/hdr-helper",self._stg_conf_file) ".config/hdr-helper")
self._conf_file_path = os.path.join(self._conf_file_dir,
self._stg_conf_file)
################################ ################################
self.default_mode = None self.default_mode = None
self.alt_rate = None self.alt_rate = None
@@ -80,6 +83,9 @@ class MonitorSetup():
file.write(line) file.write(line)
def copy_config_file(self): def copy_config_file(self):
if not os.path.exists(self._conf_file_dir):
os.makedirs(self._conf_file_dir)
# Backup existing config file if it exists # Backup existing config file if it exists
if os.path.isfile(self._conf_file_path): if os.path.isfile(self._conf_file_path):
shutil.move(self._conf_file_path, self._conf_file_path + ".backup" ) shutil.move(self._conf_file_path, self._conf_file_path + ".backup" )