[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) <mat@odoo.com>
This commit is contained in:
Martin Trigaux
2023-09-23 14:24:13 +00:00
parent b6b7af6e62
commit 07fd6277f9
+12 -8
View File
@@ -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