Skip to content

Commit

Permalink
UPD Add new option to version - override_translation to be able to ov…
Browse files Browse the repository at this point in the history
…erride i18n translations
  • Loading branch information
StephaneMangin committed Sep 3, 2024
1 parent 7457280 commit 73e0e7d
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 6 deletions.
3 changes: 2 additions & 1 deletion AUTHORS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ Contributors
- Simone Orsi (Camptocamp)
- Iván Todorovitch (Camptocamp)
- Yannick Vaucher (Camptocamp)
- Alexandre Fayolle (Camptocamp)
- Alexandre Fayolle (Camptocamp)
- Stéphane Mangin (Camptocamp)
8 changes: 7 additions & 1 deletion marabunta/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@


class Config(object):

def __init__(self,
migration_file,
database,
Expand All @@ -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,
Expand All @@ -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
Expand All @@ -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,
Expand Down Expand Up @@ -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',
Expand Down
8 changes: 6 additions & 2 deletions marabunta/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -252,17 +253,20 @@ 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:
exclude_addons = set()
install_command = self.options.install_command
install_args = self.options.install_args[:] or []
install_args += [u'--workers=0', u'--stop-after-init', u'--no-xmlrpc']
if self.override_translations:
install_args += [u'--i18n-override']

to_install = self.to_install - exclude_addons
if to_install:
Expand Down
27 changes: 25 additions & 2 deletions marabunta/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
- version: 0.0.4
backup: false
override_translations: true
addons:
upgrade:
- popeye
Expand Down Expand Up @@ -198,10 +199,27 @@ 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, override_translations=False, mode=None
):
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)
Expand Down Expand Up @@ -237,4 +255,9 @@ def _parse_version(self, parsed_version, options):
backup = True
self._parse_backup(version, backup)

# If translations needs to be overriden
self._parse_override_translations(
version, parsed_version.get("override_translations")
)

return version

0 comments on commit 73e0e7d

Please sign in to comment.