import openerp
from openerp import tools, api
from openerp.http import request
+from openerp.modules.module import get_resource_path, get_resource_from_path
from openerp.osv import fields, osv, orm
from openerp.tools import config, graph, SKIPPED_ELEMENT_TYPES
from openerp.tools.convert import _fix_multiple_roots
for view in self.browse(cr, uid, ids, context=context):
arch_fs = None
if config['dev_mode'] and view.arch_fs and view.xml_id:
- arch_fs = get_view_arch_from_file(view.arch_fs, view.xml_id)
+ # It is safe to split on / herebelow because arch_fs is explicitely stored with '/'
+ fullpath = get_resource_path(*view.arch_fs.split('/'))
+ arch_fs = get_view_arch_from_file(fullpath, view.xml_id)
result[view.id] = arch_fs or view.arch_db
return result
if context and key in context:
imd = context[key]
if self._model._name == imd['model'] and (not view.xml_id or view.xml_id == imd['xml_id']):
- data['arch_fs'] = imd['xml_file']
+ # we store the relative path to the resource instead of the absolute path
+ data['arch_fs'] = '/'.join(get_resource_from_path(imd['xml_file'])[0:2])
self.write(cr, uid, ids, data, context=context)
return True
from openerp.modules.module import get_modules, get_modules_with_version, \
load_information_from_description_file, get_module_resource, get_module_path, \
- initialize_sys_path, load_openerp_module, init_module_models, adapt_version
+ initialize_sys_path, load_openerp_module, init_module_models, adapt_version, \
+ get_resource_path, get_resource_from_path
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
return tree
-def get_module_resource(module, *args):
+def get_resource_path(module, *args):
"""Return the full path of a resource of the given module.
:param module: module name
:rtype: str
:return: absolute path to the resource
- TODO name it get_resource_path
TODO make it available inside on osv object (self.get_resource_path)
"""
mod_path = get_module_path(module)
return resource_path
return False
+# backwards compatibility
+get_module_resource = get_resource_path
+
+def get_resource_from_path(path):
+ """Tries to extract the module name and the resource's relative path
+ out of an absolute resource path.
+
+ If operation is successfull, returns a tuple containing the module name, the relative path
+ to the resource using '/' as filesystem seperator[1] and the same relative path using
+ os.path.sep seperators.
+
+ [1] same convention as the resource path declaration in manifests
+
+ :param path: absolute resource path
+
+ :rtype: tuple
+ :return: tuple(module_name, relative_path, os_relative_path) if possible, else None
+ """
+ resource = [path.replace(adpath, '') for adpath in ad_paths if path.startswith(adpath)]
+ if resource:
+ relative = resource[0].split(os.path.sep)
+ if not relative[0]:
+ relative.pop(0)
+ module = relative.pop(0)
+ return (module, '/'.join(relative), os.path.sep.join(relative))
+ return None
+
def get_module_icon(module):
iconpath = ['static', 'description', 'icon.png']
if get_module_resource(module, *iconpath):