From 07fd6277f9acc9d736bd409481022dbedf3c42ab Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Thu, 14 Sep 2023 16:06:44 +0200 Subject: [PATCH] [FIX] module: use file_path The method get_resource_path is redundant with file_path but without all the checks. The method will be deprecated in master but make it use file_path in stable. closes odoo/odoo#136272 X-original-commit: 64ab4a6914dadd741cfe61d9bd1959ae4509a1ca Signed-off-by: Martin Trigaux (mat) --- odoo/modules/module.py | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/odoo/modules/module.py b/odoo/modules/module.py index e0fcd4beb41..6ce7affeb86 100644 --- a/odoo/modules/module.py +++ b/odoo/modules/module.py @@ -18,6 +18,8 @@ import odoo import odoo.tools as tools import odoo.release as release from odoo.tools import pycompat +from odoo.tools.misc import file_path + MANIFEST_NAMES = ('__manifest__.py', '__openerp__.py') README = ['README.rst', 'README.md', 'README.txt'] @@ -138,6 +140,8 @@ def get_module_path(module, downloaded=False, display_warning=True): path if nothing else is found. """ + if re.search(r"[\/\\]", module): + return False for adp in odoo.addons.__path__: files = [opj(adp, module, manifest) for manifest in MANIFEST_NAMES] +\ [opj(adp, module + '.zip')] @@ -191,19 +195,19 @@ def get_resource_path(module, *args): :rtype: str :return: absolute path to the resource - - TODO make it available inside on osv object (self.get_resource_path) """ - mod_path = get_module_path(module) - if not mod_path: + resource_path = opj(module, *args) + try: + return file_path(resource_path) + except (FileNotFoundError, ValueError): return False - return check_resource_path(mod_path, *args) def check_resource_path(mod_path, *args): resource_path = opj(mod_path, *args) - if os.path.exists(resource_path): - return resource_path - return False + try: + return file_path(resource_path) + except (FileNotFoundError, ValueError): + return False # backwards compatibility get_module_resource = get_resource_path