From c659c1b1648f43c8796f33c03075e8aa37917dd5 Mon Sep 17 00:00:00 2001 From: Gabor Mezei Date: Tue, 6 Aug 2024 17:37:55 +0200 Subject: [PATCH] Move config file modification flag handling to the Config class Signed-off-by: Gabor Mezei --- scripts/config.py | 38 ++++++++++++++++++++------------------ 1 file changed, 20 insertions(+), 18 deletions(-) diff --git a/scripts/config.py b/scripts/config.py index 17dac4fc11..7b815e485a 100755 --- a/scripts/config.py +++ b/scripts/config.py @@ -101,21 +101,29 @@ class Config: If name is not known, raise KeyError. """ - self.settings[name].value = value + setting = self.settings[name] + if setting.configfile and setting != value: + setting.configfile.modified = True - def set(self, name, value=None): + setting.value = value + + def set(self, name, value=None, configfile=None): """Set name to the given value and make it active. If value is None and name is already known, don't change its value. - If value is None and name is not known, set its value to the empty - string. + If value is None and name is not known, set its value. """ if name in self.settings: + setting = self.settings[name] + if setting.configfile and (setting.value != value or not setting.active): + setting.configfile.modified = True if value is not None: - self.settings[name].value = value - self.settings[name].active = True + setting.value = value + setting.active = True else: - self.settings[name] = Setting(True, name, value=value) + self.settings[name] = Setting(True, name, value=value, configfile=configfile) + if configfile: + self.settings[name].configfile.modified = True def unset(self, name): """Make name unset (inactive). @@ -589,6 +597,7 @@ class MbedTLSConfig(Config): for (active, name, value, section) in self.configfile.parse_file()}) + #pylint: disable=arguments-differ def set(self, name, value=None): """Set name to the given value and make it active.""" @@ -626,6 +635,7 @@ class CryptoConfig(Config): for (active, name, value, section) in self.configfile.parse_file()}) + #pylint: disable=arguments-differ def set(self, name, value='1'): """Set name to the given value and make it active.""" @@ -684,10 +694,7 @@ class CombinedConfig(Config): else: return self.mbedtls_configfile - def __setitem__(self, name, value): - super().__setitem__(name, value) - self.settings[name].configfile.modified = True - + #pylint: disable=arguments-differ def set(self, name, value=None): """Set name to the given value and make it active.""" @@ -703,15 +710,10 @@ class CombinedConfig(Config): if not value: value = '1' - if name in self.settings: - setting = self.settings[name] - if not setting.active or (value is not None and setting.value != value): - configfile.modified = True - else: + if name not in self.settings: configfile.templates.append((name, '', '#define ' + name + ' ')) - configfile.modified = True - super().set(name, value) + super().set(name, value, configfile) def write(self, mbedtls_file=None, crypto_file=None): """Write the whole configuration to the file it was read from.