Merge branch 'FIX-prevent-error-empty-addon-path' into 'main'
[FIX] Do not crash silently, when a repos.yml file reference an empty addons folder. See merge request odoo-openupgrade-wizard/odoo-openupgrade-wizard!56
This commit is contained in:
commit
02c6fa48cf
|
|
@ -102,6 +102,15 @@ def get_base_module_folder(migration_step: dict) -> str:
|
|||
return "openerp"
|
||||
|
||||
|
||||
def get_manifest_name(migration_step: dict) -> str:
|
||||
"""return the name of the manifest file present in
|
||||
each odoo module"""
|
||||
if migration_step["version"] >= 10.0:
|
||||
return "__manifest__.py"
|
||||
|
||||
return "__openerp__.py"
|
||||
|
||||
|
||||
def skip_addon_path(migration_step: dict, path: Path) -> bool:
|
||||
"""return a boolean to indicate if the addon_path should be
|
||||
remove (during the generation of the addons_path).
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ from loguru import logger
|
|||
|
||||
from odoo_openupgrade_wizard.configuration_version_dependant import (
|
||||
get_base_module_folder,
|
||||
get_manifest_name,
|
||||
get_odoo_folder,
|
||||
get_odoo_run_command,
|
||||
get_server_wide_modules_upgrade,
|
||||
|
|
@ -47,8 +48,17 @@ def get_repo_file_path(ctx, odoo_version: float) -> Path:
|
|||
|
||||
|
||||
def get_odoo_addons_path(
|
||||
ctx, root_path: Path, migration_step: dict, execution_context: str = False
|
||||
ctx,
|
||||
odoo_env_path: Path,
|
||||
migration_step: dict,
|
||||
execution_context: str = False,
|
||||
) -> str:
|
||||
"""Return
|
||||
- addons_path: a list of Path of that contains odoo module
|
||||
for the current migration_step,
|
||||
based on the analysis of the repos.yml file
|
||||
- empty_addons_path: a list of Path of empty folders.
|
||||
(without any odoo module)"""
|
||||
repo_file = get_repo_file_path(ctx, migration_step["version"])
|
||||
base_module_folder = get_base_module_folder(migration_step)
|
||||
stream = open(repo_file, "r")
|
||||
|
|
@ -56,9 +66,10 @@ def get_odoo_addons_path(
|
|||
data = data
|
||||
|
||||
addons_path = []
|
||||
empty_addons_path = []
|
||||
odoo_folder = get_odoo_folder(migration_step, execution_context)
|
||||
for key in data.keys():
|
||||
path = root_path / Path(key)
|
||||
path = Path(key)
|
||||
if str(path).endswith(odoo_folder):
|
||||
# Add two folder for odoo folder
|
||||
addons_path.append(path / Path("addons"))
|
||||
|
|
@ -67,10 +78,21 @@ def get_odoo_addons_path(
|
|||
)
|
||||
elif skip_addon_path(migration_step, path):
|
||||
pass
|
||||
else:
|
||||
elif is_addons_path(ctx, odoo_env_path / path, migration_step):
|
||||
addons_path.append(path)
|
||||
else:
|
||||
empty_addons_path.append(path)
|
||||
|
||||
return addons_path
|
||||
return addons_path, empty_addons_path
|
||||
|
||||
|
||||
def is_addons_path(ctx, path: Path, migration_step: dict):
|
||||
for folder in [x for x in path.iterdir() if x.is_dir()]:
|
||||
if (folder / "__init__.py").exists() and (
|
||||
folder / get_manifest_name(migration_step)
|
||||
).exists():
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def get_odoo_env_path(ctx, odoo_version: float) -> Path:
|
||||
|
|
@ -123,14 +145,18 @@ def generate_odoo_command(
|
|||
)
|
||||
|
||||
# compute 'addons_path'
|
||||
addons_path = ",".join(
|
||||
[
|
||||
str(x)
|
||||
for x in get_odoo_addons_path(
|
||||
ctx, Path("/odoo_env"), migration_step, execution_context
|
||||
)
|
||||
]
|
||||
addons_path_list, empty_addons_path_list = get_odoo_addons_path(
|
||||
ctx, odoo_env_path, migration_step, execution_context
|
||||
)
|
||||
addons_path = ",".join(
|
||||
[str(Path("/odoo_env") / x) for x in addons_path_list]
|
||||
)
|
||||
for empty_addons_path in empty_addons_path_list:
|
||||
logger.info(
|
||||
"Skipping addons path"
|
||||
f" '{(odoo_env_path / empty_addons_path).resolve()}'"
|
||||
" because it doesn't contain any odoo module."
|
||||
)
|
||||
|
||||
# compute 'log_file'
|
||||
log_file_name = "{}____{}.log".format(
|
||||
|
|
|
|||
|
|
@ -379,14 +379,14 @@ class OdooModule(object):
|
|||
"""
|
||||
# Try to find the repository that contains the module
|
||||
main_path = get_odoo_env_path(ctx, current_version)
|
||||
addons_path = get_odoo_addons_path(
|
||||
addons_path, _ = get_odoo_addons_path(
|
||||
ctx,
|
||||
main_path,
|
||||
{"version": current_version, "execution_context": "openupgrade"},
|
||||
)
|
||||
for addon_path in addons_path:
|
||||
if (addon_path / module_name).exists():
|
||||
return addon_path
|
||||
if (main_path / addon_path / module_name).exists():
|
||||
return main_path / addon_path
|
||||
|
||||
return False
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user