Revision b82c4c03
[#1510] Chargement plus générique de l'application
Rend plus générique le chargement des IHMs :
- Le dossier de surcharge (public/) est pris à partir de l'emplacement
du fichier settings.ini plutôt que hard-codé.
- Idem pour le fichier app_cfg.py.
Ces modifications permettent d'héberger plusieurs instances de VigiMap
conjointement sur la même machine (par exemple, pour PreludeMap).
Change-Id: Iaf43087160023a7eda95c3d366a336ba17e0b93f
Refs: #1510.
Reviewed-on: https://vigilo-dev.si.c-s.fr/review/1926
Tested-by: Build system <qa@vigilo-dev.si.c-s.fr>
Reviewed-by: Francois POIROTTE <francois.poirotte@c-s.fr>
vigiboard/config/middleware.py | ||
---|---|---|
20 | 20 |
|
21 | 21 |
"""WSGI middleware initialization for the vigiboard application.""" |
22 | 22 |
|
23 |
from vigiboard.config.app_cfg import base_config |
|
24 |
from vigiboard.config.environment import load_environment |
|
25 |
|
|
23 |
import imp |
|
24 |
import os.path |
|
26 | 25 |
from pkg_resources import resource_filename |
27 | 26 |
from paste.cascade import Cascade |
28 | 27 |
from paste.urlparser import StaticURLParser |
29 | 28 |
|
30 | 29 |
__all__ = ['make_app'] |
31 | 30 |
|
32 |
# Use base_config to setup the necessary PasteDeploy application factory. |
|
33 |
# make_base_app will wrap the TG2 app with all the middleware it needs. |
|
34 |
make_base_app = base_config.setup_tg_wsgi_app(load_environment) |
|
35 |
|
|
36 | 31 |
|
37 | 32 |
def make_app(global_conf, full_stack=True, **app_conf): |
38 | 33 |
""" |
... | ... | |
52 | 47 |
@return: The vigiboard application with all the relevant middleware |
53 | 48 |
loaded. |
54 | 49 |
""" |
55 |
app = make_base_app(global_conf, full_stack=full_stack, **app_conf) |
|
50 |
# Charge le fichier "app_cfg.py" se trouvant aux côtés de "settings.ini". |
|
51 |
mod_info = imp.find_module('app_cfg', [ global_conf['here'] ]) |
|
52 |
app_cfg = imp.load_module('vigiboard.config.app_cfg', *mod_info) |
|
53 |
base_config = app_cfg.base_config |
|
54 |
|
|
55 |
# Initialisation de l'application et de son environnement d'exécution. |
|
56 |
load_environment = base_config.make_load_environment() |
|
57 |
make_base_app = base_config.setup_tg_wsgi_app(load_environment) |
|
58 |
app = make_base_app(global_conf, full_stack=True, **app_conf) |
|
56 | 59 |
|
57 | 60 |
max_age = app_conf.get("cache_max_age") |
58 | 61 |
try: |
... | ... | |
60 | 63 |
except (ValueError, TypeError): |
61 | 64 |
max_age = None |
62 | 65 |
|
63 |
# Personalisation des fichiers statiques via /etc/vigilo/vigiboard/public/. |
|
64 |
custom_static = StaticURLParser('/etc/vigilo/vigiboard/public/', |
|
66 |
# Personalisation des fichiers statiques via un dossier public/ |
|
67 |
# dans le répertoire contenant le fichier settings.ini chargé. |
|
68 |
custom_static = StaticURLParser(os.path.join(global_conf['here'], 'public'), |
|
65 | 69 |
cache_max_age=max_age) |
66 | 70 |
|
67 | 71 |
# On définit 2 middlewares pour fichiers statiques qui cherchent |
Also available in: Unified diff