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 f310797
Show file tree
Hide file tree
Showing 4 changed files with 175 additions and 127 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)
259 changes: 146 additions & 113 deletions marabunta/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,23 +7,25 @@


class Config(object):

def __init__(self,
migration_file,
database,
db_user=None,
db_password=None,
db_port=5432,
db_host='localhost',
mode=None,
allow_serie=False,
force_version=None,
web_host='localhost',
web_port=8069,
web_resp_status=503,
web_resp_retry_after=300, # 5 minutes
web_custom_html=None,
web_healthcheck_path=None):
def __init__(
self,
migration_file,
database,
db_user=None,
db_password=None,
db_port=5432,
db_host="localhost",
mode=None,
allow_serie=False,
force_version=None,
override_translations=False,
web_host="localhost",
web_port=8069,
web_resp_status=503,
web_resp_retry_after=300, # 5 minutes
web_custom_html=None,
web_healthcheck_path=None,
):
self.migration_file = migration_file
self.database = database
self.db_user = db_user
Expand All @@ -35,6 +37,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 Down Expand Up @@ -98,102 +101,132 @@ def get_default(self, envvar):

def get_args_parser():
"""Return a parser for command line options."""
parser = argparse.ArgumentParser(
description='Marabunta: Migrating ants for Odoo')
parser.add_argument('--migration-file', '-f',
action=EnvDefault,
envvar='MARABUNTA_MIGRATION_FILE',
required=True,
help='The yaml file containing the migration steps')
parser.add_argument('--database', '-d',
action=EnvDefault,
envvar='MARABUNTA_DATABASE',
required=True,
help="Odoo's database")
parser.add_argument('--db-user', '-u',
action=EnvDefault,
envvar='MARABUNTA_DB_USER',
required=True,
help="Odoo's database user")
parser.add_argument('--db-password', '-w',
action=EnvDefault,
envvar='MARABUNTA_DB_PASSWORD',
required=False,
help="Odoo's database password")
parser.add_argument('--db-port', '-p',
type=int,
default=os.environ.get('MARABUNTA_DB_PORT', 5432),
help="Odoo's database port")
parser.add_argument('--db-host', '-H',
default=os.environ.get('MARABUNTA_DB_HOST',
None),
help="Odoo's database host")
parser.add_argument('--mode',
action=EnvDefault,
envvar='MARABUNTA_MODE',
required=False,
help="Specify the mode in which we run the migration,"
"such as 'sample' or 'full'. Additional operations "
"of this mode will be executed after the main "
"operations and the addons list of this mode "
"will be merged with the main addons list.")
parser.add_argument('--allow-serie',
action=BoolEnvDefault,
required=False,
envvar='MARABUNTA_ALLOW_SERIE',
help='Allow to run more than 1 version upgrade at a '
'time.')
parser.add_argument('--force-version',
required=False,
default=os.environ.get('MARABUNTA_FORCE_VERSION'),
help='Force upgrade of a version, even if it has '
'already been applied.')
parser = argparse.ArgumentParser(description="Marabunta: Migrating ants for Odoo")
parser.add_argument(
"--migration-file",
"-f",
action=EnvDefault,
envvar="MARABUNTA_MIGRATION_FILE",
required=True,
help="The yaml file containing the migration steps",
)
parser.add_argument(
"--database",
"-d",
action=EnvDefault,
envvar="MARABUNTA_DATABASE",
required=True,
help="Odoo's database",
)
parser.add_argument(
"--db-user",
"-u",
action=EnvDefault,
envvar="MARABUNTA_DB_USER",
required=True,
help="Odoo's database user",
)
parser.add_argument(
"--db-password",
"-w",
action=EnvDefault,
envvar="MARABUNTA_DB_PASSWORD",
required=False,
help="Odoo's database password",
)
parser.add_argument(
"--db-port",
"-p",
type=int,
default=os.environ.get("MARABUNTA_DB_PORT", 5432),
help="Odoo's database port",
)
parser.add_argument(
"--db-host",
"-H",
default=os.environ.get("MARABUNTA_DB_HOST", None),
help="Odoo's database host",
)
parser.add_argument(
"--mode",
action=EnvDefault,
envvar="MARABUNTA_MODE",
required=False,
help="Specify the mode in which we run the migration,"
"such as 'sample' or 'full'. Additional operations "
"of this mode will be executed after the main "
"operations and the addons list of this mode "
"will be merged with the main addons list.",
)
parser.add_argument(
"--allow-serie",
action=BoolEnvDefault,
required=False,
envvar="MARABUNTA_ALLOW_SERIE",
help="Allow to run more than 1 version upgrade at a " "time.",
)
parser.add_argument(
"--force-version",
required=False,
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',
description='Configuration related to the internal web server, '
'used to publish a maintenance page during the migration.',
)
group.add_argument('--web-host',
required=False,
default=os.environ.get('MARABUNTA_WEB_HOST', '0.0.0.0'),
help='Host for the web server')
group.add_argument('--web-port',
type=int,
required=False,
default=os.environ.get('MARABUNTA_WEB_PORT', 8069),
help='Port for the web server')
group.add_argument('--web-resp-status',
type=int,
required=False,
default=os.environ.get(
'MARABUNTA_WEB_RESP_STATUS', 503
),
help='Response HTTP status code of the web server')
group.add_argument('--web-resp-retry-after',
type=int,
required=False,
default=os.environ.get(
'MARABUNTA_WEB_RESP_RETRY_AFTER', 300
),
help=(
'"Retry-After" header value (in seconds) of '
'response delivered by the web server')
)
group.add_argument('--web-custom-html',
required=False,
default=os.environ.get(
'MARABUNTA_WEB_CUSTOM_HTML'
),
help='Path to a custom html file to publish')
group.add_argument('--web-healthcheck-path',
required=False,
default=os.environ.get(
'MARABUNTA_WEB_HEALTHCHECK_PATH'
),
help=(
'URL Path used for health checks HTTP requests. '
'Such monitoring requests will return HTTP 200 '
'status code instead of the default 503.'
))
title="Web",
description="Configuration related to the internal web server, "
"used to publish a maintenance page during the migration.",
)
group.add_argument(
"--web-host",
required=False,
default=os.environ.get("MARABUNTA_WEB_HOST", "0.0.0.0"),
help="Host for the web server",
)
group.add_argument(
"--web-port",
type=int,
required=False,
default=os.environ.get("MARABUNTA_WEB_PORT", 8069),
help="Port for the web server",
)
group.add_argument(
"--web-resp-status",
type=int,
required=False,
default=os.environ.get("MARABUNTA_WEB_RESP_STATUS", 503),
help="Response HTTP status code of the web server",
)
group.add_argument(
"--web-resp-retry-after",
type=int,
required=False,
default=os.environ.get("MARABUNTA_WEB_RESP_RETRY_AFTER", 300),
help=(
'"Retry-After" header value (in seconds) of '
"response delivered by the web server"
),
)
group.add_argument(
"--web-custom-html",
required=False,
default=os.environ.get("MARABUNTA_WEB_CUSTOM_HTML"),
help="Path to a custom html file to publish",
)
group.add_argument(
"--web-healthcheck-path",
required=False,
default=os.environ.get("MARABUNTA_WEB_HEALTHCHECK_PATH"),
help=(
"URL Path used for health checks HTTP requests. "
"Such monitoring requests will return HTTP 200 "
"status code instead of the default 503."
),
)
return parser
17 changes: 6 additions & 11 deletions marabunta/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@


class Migration(object):

def __init__(self, versions, options):
self._versions = versions
self.options = options
Expand All @@ -27,7 +26,6 @@ def versions(self):


class MigrationOption(object):

def __init__(self, install_command=None, install_args=None, backup=None):
"""Options block in a migration.
Expand All @@ -38,13 +36,12 @@ def __init__(self, install_command=None, install_args=None, backup=None):
:param backup: Backup options
:type backup: Dict
"""
self.install_command = install_command or u'odoo'
self.install_args = install_args or u''
self.install_command = install_command or "odoo"
self.install_args = install_args or ""
self.backup = backup


class MigrationBackupOption(object):

def __init__(self, command, ignore_if, stop_on_failure=True):
"""Backup option in migration.
Expand Down Expand Up @@ -92,15 +89,14 @@ def command_operation(self, config):
def ignore_if_operation(self):
if self._ignore_if is None or self._ignore_if is False:
# if ignore_if parameter was not specified - always backup
return SilentOperation('false', shell=True)
return SilentOperation("false", shell=True)
elif self._ignore_if is True:
# if it is specifically True
return SilentOperation('true', shell=True)
return SilentOperation("true", shell=True)
return SilentOperation(self._ignore_if, shell=True)


class Version(object):

def __init__(self, number, options):
"""Base class for a migration version.
Expand All @@ -112,13 +108,12 @@ def __init__(self, number, options):
try:
MarabuntaVersion().parse(number)
except ValueError:
raise ConfigurationError(
u'{} is not a valid version'.format(number)
)
raise ConfigurationError("{} is not a valid version".format(number))
self.number = number
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
23 changes: 21 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,25 @@ 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(
"'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 +253,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

0 comments on commit f310797

Please sign in to comment.