(self, global_conf, app_conf, package=None, paths=None)
Initialize configuration for the application

        .. note
            This *must* be called at least once, as soon as possible
            to setup all the configuration options.

        ``global_conf``
            Several options are expected to be set for a Pylons web
            application. They will be loaded from the global_config
            which has the main Paste options. If ``debug`` is not
            enabled as a global config option, the following option
            *must* be set:

            * error_to - The email address to send the debug error to

            The optional config options in this case are:

            * smtp_server - The SMTP server to use, defaults to
              'localhost'
            * error_log - A logfile to write the error to
            * error_subject_prefix - The prefix of the error email
              subject
            * from_address - Whom the error email should be from
        ``app_conf``
            Defaults supplied via the [app:main] section from the Paste
            config file. ``load_config`` only cares about whether a
            'prefix' option is set, if so it will update Routes to
            ensure URL's take that into account.
        ``package``
            The name of the application package, to be stored in the
            app_conf.

        .. versionchanged:: 1.0
            ``template_engine`` option is no longer supported.
Initialize configuration for the application
Initialize configuration for the application
def init_app(self, global_conf, app_conf, package=None, paths=None):
        """Initialize configuration for the application

        .. note
            This *must* be called at least once, as soon as possible
            to setup all the configuration options.

        ``global_conf``
            Several options are expected to be set for a Pylons web
            application. They will be loaded from the global_config
            which has the main Paste options. If ``debug`` is not
            enabled as a global config option, the following option
            *must* be set:

            * error_to - The email address to send the debug error to

            The optional config options in this case are:

            * smtp_server - The SMTP server to use, defaults to
              'localhost'
            * error_log - A logfile to write the error to
            * error_subject_prefix - The prefix of the error email
              subject
            * from_address - Whom the error email should be from
        ``app_conf``
            Defaults supplied via the [app:main] section from the Paste
            config file. ``load_config`` only cares about whether a
            'prefix' option is set, if so it will update Routes to
            ensure URL's take that into account.
        ``package``
            The name of the application package, to be stored in the
            app_conf.

        .. versionchanged:: 1.0
            ``template_engine`` option is no longer supported.

        """
        log.debug("Initializing configuration, package: '%s'", package)

        conf = global_conf.copy()
        conf.update(app_conf)
        conf.update(dict(app_conf=app_conf, global_conf=global_conf))
        conf.update(self.pop('environment_load', {}))

        if paths:
            conf['pylons.paths'] = paths

        conf['pylons.package'] = package

        conf['debug'] = asbool(conf.get('debug'))

        # Load the MIMETypes with its default types
        MIMETypes.init()

        # Ensure all the keys from defaults are present, load them if not
        for key, val in copy.deepcopy(PylonsConfig.defaults).iteritems():
            conf.setdefault(key, val)

        # Load the errorware configuration from the Paste configuration file
        # These all have defaults, and emails are only sent if configured and
        # if this application is running in production mode
        errorware = {}
        errorware['debug'] = conf['debug']
        if not errorware['debug']:
            errorware['debug'] = False
            errorware['error_email'] = conf.get('email_to')
            errorware['error_log'] = conf.get('error_log', None)
            errorware['smtp_server'] = conf.get('smtp_server',
                'localhost')
            errorware['error_subject_prefix'] = conf.get(
                'error_subject_prefix', 'WebApp Error: ')
            errorware['from_address'] = conf.get(
                'from_address', conf.get('error_email_from',
                                         'pylons@yourapp.com'))
            errorware['error_message'] = conf.get('error_message',
                'An internal server error occurred')

        # Copy in some defaults
        if 'cache_dir' in conf:
            conf.setdefault('beaker.session.data_dir',
                            os.path.join(conf['cache_dir'], 'sessions'))
            conf.setdefault('beaker.cache.data_dir',
                            os.path.join(conf['cache_dir'], 'cache'))

        conf['pylons.cache_dir'] = conf.pop('cache_dir',
                                            conf['app_conf'].get('cache_dir'))
        # Save our errorware values
        conf['pylons.errorware'] = errorware

        # Load conf dict into self
        self.update(conf)
def init_app ( self , global_conf , app_conf , package = None , paths = None ) : log . debug ( "Initializing configuration, package: '%s'" , package ) conf = global_conf . copy ( ) conf . update ( app_conf ) conf . update ( dict ( app_conf = app_conf , global_conf = global_conf ) ) conf . update ( self . pop ( 'environment_load' , { } ) ) if paths : conf [ 'pylons.paths' ] = paths conf [ 'pylons.package' ] = package conf [ 'debug' ] = asbool ( conf . get ( 'debug' ) ) # Load the MIMETypes with its default types MIMETypes . init ( ) # Ensure all the keys from defaults are present, load them if not for key , val in copy . deepcopy ( PylonsConfig . defaults ) . iteritems ( ) : conf . setdefault ( key , val ) # Load the errorware configuration from the Paste configuration file # These all have defaults, and emails are only sent if configured and # if this application is running in production mode errorware = { } errorware [ 'debug' ] = conf [ 'debug' ] if not errorware [ 'debug' ] : errorware [ 'debug' ] = False errorware [ 'error_email' ] = conf . get ( 'email_to' ) errorware [ 'error_log' ] = conf . get ( 'error_log' , None ) errorware [ 'smtp_server' ] = conf . get ( 'smtp_server' , 'localhost' ) errorware [ 'error_subject_prefix' ] = conf . get ( 'error_subject_prefix' , 'WebApp Error: ' ) errorware [ 'from_address' ] = conf . get ( 'from_address' , conf . get ( 'error_email_from' , 'pylons@yourapp.com' ) ) errorware [ 'error_message' ] = conf . get ( 'error_message' , 'An internal server error occurred' ) # Copy in some defaults if 'cache_dir' in conf : conf . setdefault ( 'beaker.session.data_dir' , os . path . join ( conf [ 'cache_dir' ] , 'sessions' ) ) conf . setdefault ( 'beaker.cache.data_dir' , os . path . join ( conf [ 'cache_dir' ] , 'cache' ) ) conf [ 'pylons.cache_dir' ] = conf . pop ( 'cache_dir' , conf [ 'app_conf' ] . get ( 'cache_dir' ) ) # Save our errorware values conf [ 'pylons.errorware' ] = errorware # Load conf dict into self self . update ( conf )