From 211713396a77201663718eaee3d3ee6ef7805692 Mon Sep 17 00:00:00 2001 From: Antony Lesuisse Date: Mon, 26 Sep 2011 14:53:30 +0200 Subject: [PATCH] [IMP] multiple addons-path bzr revid: al@openerp.com-20110926125330-9ddpet3tdho3gq2o --- addons/web/__init__.py | 5 ++--- addons/web/common/dispatch.py | 35 +++++++++++++++-------------------- addons/web/controllers/main.py | 21 ++++++++++++--------- openerp-web.py | 2 +- 4 files changed, 30 insertions(+), 33 deletions(-) diff --git a/addons/web/__init__.py b/addons/web/__init__.py index 681fd6b..dba47c9 100644 --- a/addons/web/__init__.py +++ b/addons/web/__init__.py @@ -10,15 +10,14 @@ class Options(object): pass def wsgi_postload(): - import openerp.wsgi - import openerp.tools + import openerp import os import tempfile _logger.info("embedded mode") o = Options() o.dbfilter = openerp.tools.config['dbfilter'] o.session_storage = os.path.join(tempfile.gettempdir(), "oe-sessions") - o.addons_path = os.path.dirname(os.path.dirname(__file__)) + o.addons_path = openerp.modules.module.ad_paths o.serve_static = True o.backend = 'local' diff --git a/addons/web/common/dispatch.py b/addons/web/common/dispatch.py index b0ab780..7a293c8 100644 --- a/addons/web/common/dispatch.py +++ b/addons/web/common/dispatch.py @@ -33,7 +33,6 @@ _logger = logging.getLogger(__name__) # Globals (wont move into a pool) #----------------------------------------------------------- -applicationsession = {} addons_module = {} addons_manifest = {} controllers_class = {} @@ -52,10 +51,6 @@ class WebRequest(object): :type request: :class:`werkzeug.wrappers.BaseRequest` :param config: configuration object - .. attribute:: applicationsession - - an application-wide :class:`~collections.Mapping` - .. attribute:: httprequest the original :class:`werkzeug.wrappers.Request` object provided to the @@ -94,7 +89,6 @@ class WebRequest(object): ``bool``, indicates whether the debug mode is active on the client """ def __init__(self, request, config): - self.applicationsession = applicationsession self.httprequest = request self.httpresponse = None self.httpsession = request.session @@ -381,20 +375,21 @@ class Root(object): static URLs to the corresponding directories """ statics = {} - addons_path = self.config.addons_path - if addons_path not in sys.path: - sys.path.insert(0, addons_path) - for module in os.listdir(addons_path): - if module not in addons_module: - manifest_path = os.path.join(addons_path, module, '__openerp__.py') - path_static = os.path.join(addons_path, module, 'static') - if os.path.isfile(manifest_path) and os.path.isdir(path_static): - manifest = ast.literal_eval(open(manifest_path).read()) - _logger.info("Loading %s", module) - m = __import__(module) - addons_module[module] = m - addons_manifest[module] = manifest - statics['/%s/static' % module] = path_static + for addons_path in self.config.addons_path: + if addons_path not in sys.path: + sys.path.insert(0, addons_path) + for module in os.listdir(addons_path): + if module not in addons_module: + manifest_path = os.path.join(addons_path, module, '__openerp__.py') + path_static = os.path.join(addons_path, module, 'static') + if os.path.isfile(manifest_path) and os.path.isdir(path_static): + manifest = ast.literal_eval(open(manifest_path).read()) + manifest['addons_path'] = addons_path + _logger.info("Loading %s", module) + m = __import__(module) + addons_module[module] = m + addons_manifest[module] = manifest + statics['/%s/static' % module] = path_static for k, v in controllers_class.items(): if k not in controllers_object: o = v() diff --git a/addons/web/controllers/main.py b/addons/web/controllers/main.py index 79e2601..6b4a272 100644 --- a/addons/web/controllers/main.py +++ b/addons/web/controllers/main.py @@ -68,10 +68,12 @@ class Xml2Json: # OpenERP Web web Controllers #---------------------------------------------------------- -def manifest_glob(addons_path, addons, key): +def manifest_glob(addons, key): files = [] for addon in addons: - globlist = openerpweb.addons_manifest.get(addon, {}).get(key, []) + manifest = openerpweb.addons_manifest.get(addon, {}) + addons_path = manifest['addons_path'] + globlist = manifest.get(key, []) for pattern in globlist: for path in glob.glob(os.path.join(addons_path, addon, pattern)): files.append(path[len(addons_path):]) @@ -118,22 +120,22 @@ class WebClient(openerpweb.Controller): @openerpweb.jsonrequest def csslist(self, req, mods='web'): - return manifest_glob(req.config.addons_path, mods.split(','), 'css') + return manifest_glob(mods.split(','), 'css') @openerpweb.jsonrequest def jslist(self, req, mods='web'): - return manifest_glob(req.config.addons_path, mods.split(','), 'js') + return manifest_glob(mods.split(','), 'js') @openerpweb.httprequest def css(self, req, mods='web'): - files = manifest_glob(req.config.addons_path, mods.split(','), 'css') + files = manifest_glob(mods.split(','), 'css') content,timestamp = concat_files(req.config.addons_path, files) # TODO request set the Date of last modif and Etag return req.make_response(content, [('Content-Type', 'text/css')]) @openerpweb.httprequest def js(self, req, mods='web'): - files = manifest_glob(req.config.addons_path, mods.split(','), 'js') + files = manifest_glob(mods.split(','), 'js') content,timestamp = concat_files(req.config.addons_path, files) # TODO request set the Date of last modif and Etag return req.make_response(content, [('Content-Type', 'application/javascript')]) @@ -143,13 +145,13 @@ class WebClient(openerpweb.Controller): # script tags jslist = ['/web/webclient/js'] if req.debug: - jslist = [i + '?debug=' + str(time.time()) for i in manifest_glob(req.config.addons_path, ['web'], 'js')] + jslist = [i + '?debug=' + str(time.time()) for i in manifest_glob(['web'], 'js')] js = "\n ".join([''%i for i in jslist]) # css tags csslist = ['/web/webclient/css'] if req.debug: - csslist = [i + '?debug=' + str(time.time()) for i in manifest_glob(req.config.addons_path, ['web'], 'css')] + csslist = [i + '?debug=' + str(time.time()) for i in manifest_glob(['web'], 'css')] css = "\n ".join([''%i for i in csslist]) r = home_template % { 'javascript': js, @@ -179,7 +181,8 @@ class WebClient(openerpweb.Controller): transl = {"messages":[]} transs[addon_name] = transl for l in langs: - f_name = os.path.join(req.config.addons_path, addon_name, "po", l + ".po") + addons_path = openerpweb.addons_manifest[addon_name]['addons_path'] + f_name = os.path.join(addons_path, addon_name, "po", l + ".po") if not os.path.exists(f_name): continue try: diff --git a/openerp-web.py b/openerp-web.py index e5b28c8..928a62e 100755 --- a/openerp-web.py +++ b/openerp-web.py @@ -24,7 +24,7 @@ optparser.add_option("--server-port", dest="server_port", default=8069, help="OpenERP server port", type="int", metavar="NUMBER") optparser.add_option("--db-filter", dest="dbfilter", default='.*', help="Filter listed database", metavar="REGEXP") -optparser.add_option('--addons-path', dest='addons_path', default=path_addons, +optparser.add_option('--addons-path', dest='addons_path', default=[path_addons], action='append', help="Path do addons directory", metavar="PATH") server_options = optparse.OptionGroup(optparser, "Server configuration") -- 1.7.10.4