Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New parameter i18n override #75

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions marabunta/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def from_parse_args(cls, args):
mode=args.mode,
allow_serie=args.allow_serie,
force_version=args.force_version,
i18n_override=args.i18n_override,
web_host=args.web_host,
web_port=args.web_port,
web_resp_status=args.web_resp_status,
Expand Down Expand Up @@ -148,6 +149,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('--i18n-override',
required=False,
default=os.environ.get('MARABUNTA_I18N_OVERRIDE'),
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
11 changes: 10 additions & 1 deletion marabunta/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@

- version: 0.0.2
backup: false
override_translations: true
# nothing to do

- version: 0.0.3
Expand Down Expand Up @@ -198,9 +199,14 @@ 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_i18n_override(self, version, override_translations=False, mode=None):
if not isinstance(override_translations, bool):
raise ParseError(u"'override_translations' key must be a boolean", YAML_EXAMPLE)
Comment on lines +203 to +204
Copy link

@SilvioC2C SilvioC2C Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Checks are failing because the method receives None for override_translations, and the instance check against bool type fails.
Maybe you can normalize the variable before the check like this:

Suggested change
if not isinstance(override_translations, bool):
raise ParseError(u"'override_translations' key must be a boolean", YAML_EXAMPLE)
override_translations = override_translations or False
if not isinstance(override_translations, bool):
raise ParseError(u"'override_translations' key must be a boolean", YAML_EXAMPLE)

or:

Suggested change
if not isinstance(override_translations, bool):
raise ParseError(u"'override_translations' key must be a boolean", YAML_EXAMPLE)
if override_translations not in (None, True, False):
raise ParseError(u"'override_translations' key must be None or a boolean", YAML_EXAMPLE)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too soon bro' ^^

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But comment taken in account

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was waiting for a DB migration to complete and I saw this PR, so I took the chance to give it a read even if it was in draft 😄

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nexyt PR, the good one ^^ #76

version.override_translations = override_translations

def _parse_version(self, parsed_version, options):
self.check_dict_expected_keys(
{'version', 'operations', 'addons', 'modes', 'backup'},
{'version', 'operations', 'addons', 'modes', 'backup', 'override_translations'},
parsed_version, 'versions',
)
number = parsed_version.get('version')
Expand Down Expand Up @@ -237,4 +243,7 @@ def _parse_version(self, parsed_version, options):
backup = True
self._parse_backup(version, backup)

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

return version
Loading