diff --git a/NEWS.rst b/NEWS.rst index 128401348e8fe67619900cc42d718c63867aac0d_TkVXUy5yc3Q=..76eb4ecdaacf0321ba8b04ca3e3d4d527a9686a8_TkVXUy5yc3Q= 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -9,6 +9,8 @@ Push image to our registry too. +More options can be expanded. + 7.0.3 ----- diff --git a/odoo_scripts/config.py b/odoo_scripts/config.py index 128401348e8fe67619900cc42d718c63867aac0d_b2Rvb19zY3JpcHRzL2NvbmZpZy5weQ==..76eb4ecdaacf0321ba8b04ca3e3d4d527a9686a8_b2Rvb19zY3JpcHRzL2NvbmZpZy5weQ== 100644 --- a/odoo_scripts/config.py +++ b/odoo_scripts/config.py @@ -125,6 +125,39 @@ for key in ("db_user", "db_password", "load-language"): setattr(self, key_format(key), section.get(key, None)) + def read_expanded( + key: str, default_value=None, always_set: bool = False + ): + """Read from local version, or from expanded if value is found. + Raise an exception if more than one value is found.""" + value = default_value + if toread(key): + found = False + for config in self._expanded_configuration.values(): + if hasattr(config, key): + if found: + raise Exception( + "Key %s to read in several expanded " + "configurations" % key + ) + else: + value = getattr(config, key) + found = True + if key in section: + local_value = section.get(key, default_value) + if ( + found + and value != default_value + and local_value != value + ): + raise Exception( + "Key %s in expanded configuration and locally set" + " with different values" % key + ) + value = local_value + if toread(key) or always_set: + setattr(self, key, value) + self.registry = section.get("registry", "registry.xcg.io") project_path = os.path.realpath(".") self.image = section.get("image", os.path.basename(project_path)) @@ -128,7 +161,7 @@ self.registry = section.get("registry", "registry.xcg.io") project_path = os.path.realpath(".") self.image = section.get("image", os.path.basename(project_path)) - self.odoo_type = section.get("odoo_type", "odoo7") + read_expanded("odoo_type", "odoo7", always_set=True) if self.odoo_type not in ( "odoo7", "odoo8", @@ -137,7 +170,7 @@ "odoo13", ): _logger.warning("Unexpected odoo_type: %s", self.odoo_type) - self.postgresql_version = section.get("postgresql_version", "9.6") + read_expanded("postgresql_version", "9.6") self.start_py3o = section.get("start_py3o", "no") in ("yes", "true")