[REF] add mutualized options in cli_options.py file ;

[ADD] project-name argument in init step to have the possibility to have a friendly tag for the odoo docker images ;
This commit is contained in:
Sylvain LE GAL 2022-04-09 00:49:53 +02:00
parent f4bb696f4e
commit 917692d0fb
8 changed files with 59 additions and 10 deletions

View File

@ -2,6 +2,10 @@ import click
import docker
from loguru import logger
from odoo_openupgrade_wizard.cli_options import (
get_odoo_versions_from_options,
releases_options,
)
from odoo_openupgrade_wizard.configuration_version_dependant import (
get_docker_image_tag,
get_odoo_env_path,
@ -9,14 +13,14 @@ from odoo_openupgrade_wizard.configuration_version_dependant import (
@click.command()
@releases_options
@click.pass_context
def docker_build(ctx):
def docker_build(ctx, releases):
"""Build Odoo Docker Images. (One image per release)"""
# TODO, make it modular.
# For exemple, possibility to aggregate only 9.0 and 11.0 release
docker_client = docker.from_env()
for odoo_version in ctx.obj["config"]["odoo_versions"]:
for odoo_version in get_odoo_versions_from_options(ctx, releases):
logger.info(
"Building Odoo docker image for release '%s'. "
"This can take a while..." % (odoo_version["release"])

View File

@ -1,5 +1,9 @@
import click
from odoo_openupgrade_wizard.cli_options import (
get_odoo_versions_from_options,
releases_options,
)
from odoo_openupgrade_wizard.configuration_version_dependant import (
get_odoo_env_path,
)
@ -7,13 +11,12 @@ from odoo_openupgrade_wizard.tools_system import git_aggregate
@click.command()
@releases_options
@click.pass_context
def get_code(ctx):
def get_code(ctx, releases):
"""Get code by running gitaggregate command for each release"""
# TODO, make it modular.
# For exemple, possibility to aggregate only 9.0 and 11.0 release
for odoo_version in ctx.obj["config"]["odoo_versions"]:
for odoo_version in get_odoo_versions_from_options(ctx, releases):
folder_path = get_odoo_env_path(ctx, odoo_version)
repo_file_path = folder_path / "repos.yml"
git_aggregate(folder_path, repo_file_path)

View File

@ -15,6 +15,15 @@ from odoo_openupgrade_wizard.tools_system import (
@click.command()
@click.option(
"--project-name",
required=True,
prompt=True,
type=str,
help="Name of your project without spaces neither special chars."
" exemple 'my-customer-9-12'. This will be used to tag with a friendly"
" name the odoo docker images.",
)
@click.option(
"--initial-release",
required=True,
@ -35,7 +44,9 @@ from odoo_openupgrade_wizard.tools_system import (
"Ex: 'OCA/web,OCA/server-tools,GRAP/grap-odoo-incubator'",
)
@click.pass_context
def init(ctx, initial_release, final_release, extra_repository_list):
def init(
ctx, project_name, initial_release, final_release, extra_repository_list
):
"""Initialize OpenUpgrade Wizard Environment based on the initial and
the final release of Odoo you want to migrate.
"""
@ -105,6 +116,7 @@ def init(ctx, initial_release, final_release, extra_repository_list):
ensure_file_exists_from_template(
ctx.obj["config_file_path"],
templates.CONFIG_YML_TEMPLATE,
project_name=project_name,
steps=steps,
odoo_versions=odoo_versions,
)

View File

@ -0,0 +1,24 @@
import click
def releases_options(function):
function = click.option(
"--releases",
type=str,
help="Coma-separated values of odoo releases for which"
" you want to perform the operation.",
)(function)
return function
def get_odoo_versions_from_options(ctx, releases_arg):
if not releases_arg:
return ctx.obj["config"]["odoo_versions"]
else:
odoo_versions = []
releases = [float(x) for x in releases_arg.split(",")]
for odoo_version in ctx.obj["config"]["odoo_versions"]:
if odoo_version["release"] in releases:
odoo_versions.append(odoo_version)
return odoo_versions

View File

@ -1,4 +1,6 @@
CONFIG_YML_TEMPLATE = """odoo_versions:
CONFIG_YML_TEMPLATE = """project_name: {{ project_name }}
odoo_versions:
{% for odoo_version in odoo_versions %}
- release: {{ odoo_version['release'] }}
{% endfor %}

View File

@ -16,6 +16,7 @@ def test_cli_init():
[
"--env-folder=%s" % output_folder_path,
"init",
"--project-name=test-cli-init",
"--initial-release=9.0",
"--final-release=12.0",
"--extra-repository="

View File

@ -17,6 +17,7 @@ def test_cli_get_code():
[
"--env-folder=%s" % output_folder_path,
"init",
"--project-name=test-cli-get-code",
"--initial-release=14.0",
"--final-release=14.0",
"--extra-repository=OCA/web",

View File

@ -1,3 +1,5 @@
project_name: test-cli-init
odoo_versions:
- release: 9.0