# HG changeset patch # User Vincent Hatakeyama <vincent.hatakeyama@xcg-consulting.fr> # Date 1615308175 -3600 # Tue Mar 09 17:42:55 2021 +0100 # Node ID 76eb4ecdaacf0321ba8b04ca3e3d4d527a9686a8 # Parent 128401348e8fe67619900cc42d718c63867aac0d ✨ more options can be expanded diff --git a/NEWS.rst b/NEWS.rst --- 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 --- a/odoo_scripts/config.py +++ b/odoo_scripts/config.py @@ -125,10 +125,43 @@ 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)) - 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")