[Mpuls-commits] r5815 - in base/trunk/mpulsweb: config lib

scm-commit at wald.intevation.org scm-commit at wald.intevation.org
Mon Feb 13 10:41:12 CET 2012


Author: roland
Date: 2012-02-13 10:41:12 +0100 (Mon, 13 Feb 2012)
New Revision: 5815

Modified:
   base/trunk/mpulsweb/config/environment.py
   base/trunk/mpulsweb/config/importer.py
   base/trunk/mpulsweb/config/middleware.py
   base/trunk/mpulsweb/config/routing.py
   base/trunk/mpulsweb/lib/app_globals.py
   base/trunk/mpulsweb/lib/base.py
Log:
issue2829: change the handling of config object, which changed in pylons 0.10
in debian squeeze


Modified: base/trunk/mpulsweb/config/environment.py
===================================================================
--- base/trunk/mpulsweb/config/environment.py	2012-02-13 09:39:24 UTC (rev 5814)
+++ base/trunk/mpulsweb/config/environment.py	2012-02-13 09:41:12 UTC (rev 5815)
@@ -30,7 +30,7 @@
 from mako.lookup import TemplateLookup
 from pylons.error import handle_mako_error
 
-from pylons import config
+from pylons.configuration import PylonsConfig
 
 import mpulsweb.lib.helpers
 from mpulsweb.config.routing import make_map
@@ -42,6 +42,8 @@
 
 def load_environment(global_conf, app_conf):
     """Configure the Pylons environment via the ``pylons.config`` object"""
+    config = PylonsConfig()
+
     def get(item):
         """Lookup item in app_conf and global_conf.  Return the first one found.
         If item is found in neither, None is returned.
@@ -91,8 +93,9 @@
     config.init_app(global_conf, app_conf, package='mpulsweb',
                     template_engine='mako', paths=paths)
 
-    config['routes.map'] = make_map()
-    config['pylons.g'] = import_overridable_module("lib.app_globals").Globals()
+    config['routes.map'] = make_map(config)
+    app_globals_module = import_overridable_module("lib.app_globals", config)
+    config['pylons.g'] = app_globals_module.Globals(config)
     config['pylons.h'] = mpulsweb.lib.helpers
 
     # Create the Mako TemplateLookup, with the default auto-escaping
@@ -106,5 +109,5 @@
                        input_encoding='utf-8', default_filters=['escape'],
                        imports=['from webhelpers.html import escape'])
 
-    # CONFIGURATION OPTIONS HERE (note: all config options will override
-    # any Pylons config options)
+
+    return config

Modified: base/trunk/mpulsweb/config/importer.py
===================================================================
--- base/trunk/mpulsweb/config/importer.py	2012-02-13 09:39:24 UTC (rev 5814)
+++ base/trunk/mpulsweb/config/importer.py	2012-02-13 09:41:12 UTC (rev 5815)
@@ -5,13 +5,13 @@
 
 from paste.util.import_string import try_import_module, import_module
 
-from pylons import config
+from pylons import config as pylons_config
 
 
 log = logging.getLogger(__name__)
 
 
-def import_overridable_module(modulename):
+def import_overridable_module(modulename, config=None):
     """Import a module that an MPuls specialization can override.
 
     The modulename should be a name relative to the mpulsweb package,
@@ -25,6 +25,8 @@
     raised (most likely an ImportError).
     """
 
+    if config is None:
+        config = pylons_config
     # Append root dir of the application configuration to the pythonpath
     app_root = config.get('mpuls.app.root')
     if app_root not in sys.path:

Modified: base/trunk/mpulsweb/config/middleware.py
===================================================================
--- base/trunk/mpulsweb/config/middleware.py	2012-02-13 09:39:24 UTC (rev 5814)
+++ base/trunk/mpulsweb/config/middleware.py	2012-02-13 09:41:12 UTC (rev 5815)
@@ -9,7 +9,6 @@
 from paste.registry import RegistryManager
 from paste.urlparser import StaticURLParser
 from paste.deploy.converters import asbool
-from pylons import config
 from pylons.util import  class_name_from_module_name
 from pylons.middleware import ErrorHandler, StatusCodeRedirect
 from pylons.wsgiapp import PylonsApp
@@ -62,7 +61,8 @@
         __traceback_hide__ = 'before_and_this'
 
         module = import_overridable_module("controllers."
-                                           + controller.replace('/', '.'))
+                                           + controller.replace('/', '.'),
+                                           self.config)
 
         if hasattr(module, '__controller__'):
             mycontroller = getattr(module, module.__controller__)
@@ -101,12 +101,12 @@
 
     """
     # Configure the Pylons environment
-    load_environment(global_conf, app_conf)
+    config = load_environment(global_conf, app_conf)
 
     # Set locale
     locale.setlocale(locale.LC_ALL, global_conf.get('locale', 'de_DE'))
     # The Pylons WSGI app
-    app = MyPylonsApp()
+    app = MyPylonsApp(config=config)
 
     # Pylon's exception handler (at least the debug handler) sometimes
     # has problems with exceptions whose messages are byte-strings
@@ -147,6 +147,7 @@
                        for path in config['pylons.paths']['static_files']]
         app = Cascade(static_apps + [app])
 
+    app.config = config
     return app
 
 

Modified: base/trunk/mpulsweb/config/routing.py
===================================================================
--- base/trunk/mpulsweb/config/routing.py	2012-02-13 09:39:24 UTC (rev 5814)
+++ base/trunk/mpulsweb/config/routing.py	2012-02-13 09:41:12 UTC (rev 5815)
@@ -33,7 +33,6 @@
 import re
 import logging
 
-from pylons import config
 from routes import Mapper
 
 import mpulsweb.controllers
@@ -70,7 +69,7 @@
     log.debug('Found controllers: %s' % controllers)
     return controllers
 
-def make_map():
+def make_map(config):
     """Create, configure and return the routes Mapper"""
     # First try to search to controllers in the instance (WASKO, WASKA, JMD ...)
     controller_dirs = []

Modified: base/trunk/mpulsweb/lib/app_globals.py
===================================================================
--- base/trunk/mpulsweb/lib/app_globals.py	2012-02-13 09:39:24 UTC (rev 5814)
+++ base/trunk/mpulsweb/lib/app_globals.py	2012-02-13 09:41:12 UTC (rev 5815)
@@ -32,8 +32,6 @@
 from paste.reloader import watch_file
 from paste.registry import StackedObjectProxy
 
-from pylons import config
-
 from formed.meta.io.document import openDocument
 
 from libmpuls.service.tags import TagSetterConfig
@@ -56,7 +54,7 @@
 session = StackedObjectProxy()
 
 
-def ssl_option(key, default=None):
+def ssl_option(config, key, default=None):
     """Return the SSL option named by key.
 
     The SSL option is taken from pylons config with a key formed by
@@ -67,13 +65,13 @@
     return config.get("mpuls.meta.ssl." + key, default)
 
 
-def ssl_file_option(key, default=None):
+def ssl_file_option(config, key, default=None):
     """Like ssl_option, but for values that are filenames.
     The filenames are added to the paster reloader watch list, so that
     when the application runs with 'paster serve --reload' paster
     restarts automatically when the file changes.
     """
-    filename = ssl_option(key, default=None)
+    filename = ssl_option(config, key, default=None)
     watch_file(filename)
     return filename
 
@@ -84,7 +82,7 @@
     life of the application
     """
 
-    def __init__(self):
+    def __init__(self, config):
         """One instance of Globals is created during application
         initialization and is available during requests via the 'g'
         variable
@@ -142,10 +140,13 @@
         watch_file(tagging_file)
 
         # meta-server settings
-        if ssl_option("enabled", "false") == "true":
-            self.ssl_context = get_ssl_context(ssl_file_option("cacerts"),
-                                               ssl_file_option("client_cert"),
-                                               ssl_file_option("client_key"))
+        if ssl_option(config, "enabled", "false") == "true":
+            self.ssl_context = get_ssl_context(ssl_file_option(config,
+                                                               "cacerts"),
+                                               ssl_file_option(config,
+                                                               "client_cert"),
+                                               ssl_file_option(config,
+                                                               "client_key"))
         else:
             self.ssl_context = None
 
@@ -158,14 +159,14 @@
         # are not related to any global vars or functions. Move to
         # config/environment.py
 
-        self._init_case()
+        self._init_case(config)
 
-    def _init_case(self):
+    def _init_case(self, config):
         from mpulsweb.model.agency import MpulsAgencyFactory, MpulsAgency
         from mpulsweb.model.case import MpulsCase, MpulsCaseFactory
         """Set the mpuls application specific case classes"""
         try:
-            case_module = import_overridable_module("model.case")
+            case_module = import_overridable_module("model.case", config)
             Case = case_module.Case
             self.case = Case
             CaseFactory = case_module.CaseFactory
@@ -182,7 +183,7 @@
 
         self.agency_factory = MpulsAgencyFactory(self.agency)
 
-        search_module = import_overridable_module("lib.search")
+        search_module = import_overridable_module("lib.search", config)
         self.case_search = search_module.CaseSearch(
             self.case_factory.get_search_retrieve_fields(),
             self.case_factory.get_search_match_fields())

Modified: base/trunk/mpulsweb/lib/base.py
===================================================================
--- base/trunk/mpulsweb/lib/base.py	2012-02-13 09:39:24 UTC (rev 5814)
+++ base/trunk/mpulsweb/lib/base.py	2012-02-13 09:41:12 UTC (rev 5815)
@@ -189,6 +189,8 @@
                               read_only=read_only)
 
     def __before__(self, environ):
+        import pprint
+        pprint.pprint(environ)
         mpuls_session_module = import_overridable_module("lib.session")
         environ['paste.registry'].register(session,
                                            mpuls_session_module.MPulsSession())
@@ -227,7 +229,10 @@
                                               config.get('mpuls.db.port'),
                                               config.get('mpuls.db.database'),
                                               config.get('mpuls.db.user'))
-
+            log.debug("DB parameters: %r", db_parameters)
+            import pprint
+            pprint.pprint(config.items())
+            DBNameContextFilter.set_thread_dbname(db_parameters["database"])
             self.db = db.DB(**db_parameters)
             db.enter(self.db)
 



More information about the Mpuls-commits mailing list