From 9d6dac591c5682d493e1aceba7b3efb5ff4a29ed Mon Sep 17 00:00:00 2001 From: Stephane Mangin Date: Tue, 3 Sep 2024 17:14:03 +0200 Subject: [PATCH] UPD Add new option to version - override_translation to be able to override i18n translations --- AUTHORS.rst | 3 ++- HISTORY.rst | 6 +++++ README.rst | 57 ++++++++++++++++++++++++--------------------- marabunta/config.py | 8 ++++++- marabunta/model.py | 10 ++++++-- marabunta/parser.py | 24 +++++++++++++++++-- 6 files changed, 75 insertions(+), 33 deletions(-) diff --git a/AUTHORS.rst b/AUTHORS.rst index f539e9d..fa07642 100644 --- a/AUTHORS.rst +++ b/AUTHORS.rst @@ -11,4 +11,5 @@ Contributors - Simone Orsi (Camptocamp) - Iván Todorovitch (Camptocamp) - Yannick Vaucher (Camptocamp) -- Alexandre Fayolle (Camptocamp) \ No newline at end of file +- Alexandre Fayolle (Camptocamp) +- Stéphane Mangin (Camptocamp) diff --git a/HISTORY.rst b/HISTORY.rst index 57ad0fc..7d004c1 100644 --- a/HISTORY.rst +++ b/HISTORY.rst @@ -14,6 +14,12 @@ Unreleased **Improvements** +* I18N overwrite option + + Migration allows using a `override_translations` version's option in order to + allow usage of Odoo parameter `--i18n-overwrite`. + Command option is `MARABUNTA_OVERRIDE_TRANSLATIONS` + **Build** * Depend on psycopg2 rather than psycopg2-binary diff --git a/README.rst b/README.rst index 2312182..70f0a0f 100644 --- a/README.rst +++ b/README.rst @@ -36,33 +36,35 @@ Although the first marabunta version must be **setup** for the initial setup of Options ======= - +-------------------+----------+---------------------------+-------------------------------------------------------------------+ - | option | shortcut | envvar | purpose | - +===================+==========+===========================+===================================================================+ - | --migration-file | -f | MARABUNTA_MIGRATION_FILE | Definition file for the migration. | - +-------------------+----------+---------------------------+-------------------------------------------------------------------+ - | --database | -d | MARABUNTA_DATABASE | Database we want to run the migration on. | - +-------------------+----------+---------------------------+-------------------------------------------------------------------+ - | --db-user | -u | MARABUNTA_DB_USER | Database user. | - +-------------------+----------+---------------------------+-------------------------------------------------------------------+ - | --db-password | -w | MARABUNTA_DB_PASSWORD | Database password. | - +-------------------+----------+---------------------------+-------------------------------------------------------------------+ - | --db-port | -p | MARABUNTA_DB_PORT | Database port (defaults to 5432). | - +-------------------+----------+---------------------------+-------------------------------------------------------------------+ - | --db-host | -H | MARABUNTA_DB_HOST | Database port (defaults to None). | - +-------------------+----------+---------------------------+-------------------------------------------------------------------+ - | --mode | | MARABUNTA_MODE | Mode marabunta runs in for different envs. | - +-------------------+----------+---------------------------+-------------------------------------------------------------------+ - | --allow-serie | | MARABUNTA_ALLOW_SERIE | Allow multiple versions to be upgraded at once. | - +-------------------+----------+---------------------------+-------------------------------------------------------------------+ - | --force-version | | MARABUNTA_FORCE_VERSION | Force the upgrade to a version no matter what. | - +-------------------+----------+---------------------------+-------------------------------------------------------------------+ - | --web-host | | MARABUNTA_WEB_HOST | Interface to bind for the maintenance page. (defaults to 0.0.0.0).| - +-------------------+----------+---------------------------+-------------------------------------------------------------------+ - | --web-port | | MARABUNTA_WEB_PORT | Port for the maintenance page. (defaults to 8069). | - +-------------------+----------+---------------------------+-------------------------------------------------------------------+ - | --web-custom-html | | MARABUNTA_WEB_CUSTOM_HTML | Path to custom maintenance html page to serve. | - +-------------------+----------+---------------------------+-------------------------------------------------------------------+ + +-------------------------+----------+---------------------------------+-------------------------------------------------------------------+ + | option | shortcut | envvar | purpose | + +=========================+==========+=================================+===================================================================+ + | --migration-file | -f | MARABUNTA_MIGRATION_FILE | Definition file for the migration. | + +-------------------------+----------+---------------------------------+-------------------------------------------------------------------+ + | --database | -d | MARABUNTA_DATABASE | Database we want to run the migration on. | + +-------------------------+----------+---------------------------------+-------------------------------------------------------------------+ + | --db-user | -u | MARABUNTA_DB_USER | Database user. | + +-------------------------+----------+---------------------------------+-------------------------------------------------------------------+ + | --db-password | -w | MARABUNTA_DB_PASSWORD | Database password. | + +-------------------------+----------+---------------------------------+-------------------------------------------------------------------+ + | --db-port | -p | MARABUNTA_DB_PORT | Database port (defaults to 5432). | + +-------------------------+----------+---------------------------------+-------------------------------------------------------------------+ + | --db-host | -H | MARABUNTA_DB_HOST | Database port (defaults to None). | + +-------------------------+----------+---------------------------------+-------------------------------------------------------------------+ + | --mode | | MARABUNTA_MODE | Mode marabunta runs in for different envs. | + +-------------------------+----------+---------------------------------+-------------------------------------------------------------------+ + | --allow-serie | | MARABUNTA_ALLOW_SERIE | Allow multiple versions to be upgraded at once. | + +-------------------------+----------+---------------------------------+-------------------------------------------------------------------+ + | --force-version | | MARABUNTA_FORCE_VERSION | Force the upgrade to a version no matter what. | + +-------------------------+----------+---------------------------------+-------------------------------------------------------------------+ + | --override-translations | | MARABUNTA_OVERRIDE_TRANSLATIONS | Force translations override | + +-------------------------+----------+---------------------------------+-------------------------------------------------------------------+ + | --web-host | | MARABUNTA_WEB_HOST | Interface to bind for the maintenance page. (defaults to 0.0.0.0).| + +-------------------------+----------+---------------------------------+-------------------------------------------------------------------+ + | --web-port | | MARABUNTA_WEB_PORT | Port for the maintenance page. (defaults to 8069). | + +-------------------------+----------+---------------------------------+-------------------------------------------------------------------+ + | --web-custom-html | | MARABUNTA_WEB_CUSTOM_HTML | Path to custom maintenance html page to serve. | + +-------------------------+----------+---------------------------------+-------------------------------------------------------------------+ YAML layout & Example ===================== @@ -119,6 +121,7 @@ Here is an Example migration file:: - version: 0.0.4 backup: false + override_translations: true addons: upgrade: - popeye diff --git a/marabunta/config.py b/marabunta/config.py index aa890d6..99dfb41 100644 --- a/marabunta/config.py +++ b/marabunta/config.py @@ -7,7 +7,6 @@ class Config(object): - def __init__(self, migration_file, database, @@ -18,6 +17,7 @@ def __init__(self, mode=None, allow_serie=False, force_version=None, + override_translations=False, web_host='localhost', web_port=8069, web_resp_status=503, @@ -35,6 +35,7 @@ def __init__(self, self.force_version = force_version if force_version and not allow_serie: self.allow_serie = True + self.override_translations = override_translations self.web_host = web_host self.web_port = web_port self.web_resp_status = web_resp_status @@ -60,6 +61,7 @@ def from_parse_args(cls, args): mode=args.mode, allow_serie=args.allow_serie, force_version=args.force_version, + override_translations=args.override_translations, web_host=args.web_host, web_port=args.web_port, web_resp_status=args.web_resp_status, @@ -148,6 +150,10 @@ def get_args_parser(): default=os.environ.get('MARABUNTA_FORCE_VERSION'), help='Force upgrade of a version, even if it has ' 'already been applied.') + parser.add_argument("--override-translations", + required=False, + default=os.environ.get("MARABUNTA_OVERRIDE_TRANSLATIONS"), + help="Force override of translations.") group = parser.add_argument_group( title='Web', diff --git a/marabunta/model.py b/marabunta/model.py index 391904a..b908d1a 100644 --- a/marabunta/model.py +++ b/marabunta/model.py @@ -119,6 +119,7 @@ def __init__(self, number, options): self._version_modes = {} self.options = options self.backup = False + self.override_translations = False def is_processed(self, db_versions): """Check if version is already applied in the database. @@ -210,7 +211,7 @@ def upgrade_addons_operation(self, addons_state, mode=None): to_install = addons_list - installed to_upgrade = installed & addons_list - return UpgradeAddonsOperation(self.options, to_install, to_upgrade) + return UpgradeAddonsOperation(self.options, to_install, to_upgrade, self.override_translations) def remove_addons_operation(self): raise NotImplementedError @@ -252,10 +253,11 @@ def add_remove_addons(self, addons): class UpgradeAddonsOperation(object): - def __init__(self, options, to_install, to_upgrade): + def __init__(self, options, to_install, to_upgrade, override_translations=False): self.options = options self.to_install = set(to_install) self.to_upgrade = set(to_upgrade) + self.override_translations = override_translations def operation(self, exclude_addons=None): if exclude_addons is None: @@ -273,6 +275,10 @@ def operation(self, exclude_addons=None): install_args += [u'-u', u','.join(to_upgrade)] if to_install or to_upgrade: + # if we don't have addons to install or upgrade, an issue will + # be raised by Odoo if we add the `--i18n-overwrite` flag + if self.override_translations: + install_args += [u'--i18n-overwrite'] return Operation([install_command] + install_args) else: return Operation('') diff --git a/marabunta/parser.py b/marabunta/parser.py index 0216ca9..cc3f953 100644 --- a/marabunta/parser.py +++ b/marabunta/parser.py @@ -71,6 +71,7 @@ - version: 0.0.4 backup: false + override_translations: true addons: upgrade: - popeye @@ -198,10 +199,26 @@ def _parse_backup(self, version, backup=True, mode=None): raise ParseError(u"'backup' key must be a boolean", YAML_EXAMPLE) version.backup = backup + def _parse_override_translations(self, version, parsed_version): + override_translations = parsed_version.get('override_translations') + if override_translations not in (True, False, None): + raise ParseError( + "'override_translations' key must be a boolean", YAML_EXAMPLE + ) + version.override_translations = override_translations + def _parse_version(self, parsed_version, options): self.check_dict_expected_keys( - {'version', 'operations', 'addons', 'modes', 'backup'}, - parsed_version, 'versions', + { + "version", + "operations", + "addons", + "modes", + "backup", + "override_translations", + }, + parsed_version, + "versions", ) number = parsed_version.get('version') version = Version(number, options) @@ -237,4 +254,7 @@ def _parse_version(self, parsed_version, options): backup = True self._parse_backup(version, backup) + # If translations needs to be overridden + self._parse_override_translations(version, parsed_version) + return version