示例#1
0
def load_config(ini_file, log_from_ini=False, do_logging=True):
    from paste.deploy import appconfig
    from desio.config.environment import load_environment

    ini_file = os.path.abspath(ini_file)
    # load config / pylons environment
    # note: appconfig (as opposed to loadapp) doesn't load wsgi
    app_config = appconfig("config:%s" % (ini_file, ))
    config = load_environment(app_config.global_conf, app_config.local_conf)
    from desio import model

    engine = config['pylons.app_globals'].sa_default_engine
    model.init_model(engine)
    pylons.config.push_process_config(config)

    if not do_logging:
        return

    if log_from_ini:
        try:
            # this fails because I want it to fail.
            logging.config.fileConfig(ini_file)
        except Exception, e:
            import traceback
            sys.stderr.write(traceback.format_exc())
        else:
            return
示例#2
0
def load_config(ini_file, log_from_ini=False, do_logging=True):
    from paste.deploy import appconfig
    from desio.config.environment import load_environment

    ini_file = os.path.abspath(ini_file)
    # load config / pylons environment
    # note: appconfig (as opposed to loadapp) doesn't load wsgi
    app_config = appconfig("config:%s" % (ini_file,))
    config = load_environment(app_config.global_conf, app_config.local_conf)
    from desio import model

    engine = config["pylons.app_globals"].sa_default_engine
    model.init_model(engine)
    pylons.config.push_process_config(config)

    if not do_logging:
        return

    if log_from_ini:
        try:
            # this fails because I want it to fail.
            logging.config.fileConfig(ini_file)
        except Exception, e:
            import traceback

            sys.stderr.write(traceback.format_exc())
        else:
            return
示例#3
0
def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    config = PylonsConfig()

    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[os.path.join(root, 'templates')])

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='desio', paths=paths)

    config['routes.map'] = make_map(config)
    config['pylons.app_globals'] = app_globals.Globals(config)
    config['pylons.h'] = desio.lib.helpers
    config['pylons.strict_tmpl_context'] = False

    config['beaker.session.cookie_expires'] = None

    # Setup cache object as early as possible
    import pylons
    pylons.cache._push_object(config['pylons.app_globals'].cache)

    # Create the Mako TemplateLookup, with the default auto-escaping
    config['pylons.app_globals'].mako_lookup = TemplateLookup(
        directories=paths['templates'],
        error_handler=handle_mako_error,
        module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
        input_encoding='utf-8',
        default_filters=['escape'],
        imports=['from webhelpers.html import escape'])

    # Setup the SQLAlchemy database engine
    config['pylons.app_globals'].sa_default_engine = engine_from_config(
        config, 'sqlalchemy.default.', proxy=TimerProxy())
    init_model(config['pylons.app_globals'].sa_default_engine)

    config['pylons.errorware']['smtp_username'] = config.get('smtp_username')
    config['pylons.errorware']['smtp_password'] = config.get('smtp_password')
    config['pylons.errorware']['smtp_use_tls'] = config.get('smtp_use_tls')
    config['pylons.errorware']['smtp_port'] = config.get('smtp_port')

    # CONFIGURATION OPTIONS HERE (note: all config options will override
    # any Pylons config options)
    fs.setup_directories(config)
    setup_turbomail(config)

    return config
示例#4
0
def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    config = PylonsConfig()
    
    # Pylons paths
    root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    paths = dict(root=root,
                 controllers=os.path.join(root, 'controllers'),
                 static_files=os.path.join(root, 'public'),
                 templates=[os.path.join(root, 'templates')])

    # Initialize config with the basic options
    config.init_app(global_conf, app_conf, package='desio', paths=paths)

    config['routes.map'] = make_map(config)
    config['pylons.app_globals'] = app_globals.Globals(config)
    config['pylons.h'] = desio.lib.helpers
    config['pylons.strict_tmpl_context'] = False
    
    config['beaker.session.cookie_expires'] = None
    
    # Setup cache object as early as possible
    import pylons
    pylons.cache._push_object(config['pylons.app_globals'].cache)
    

    # Create the Mako TemplateLookup, with the default auto-escaping
    config['pylons.app_globals'].mako_lookup = TemplateLookup(
        directories=paths['templates'],
        error_handler=handle_mako_error,
        module_directory=os.path.join(app_conf['cache_dir'], 'templates'),
        input_encoding='utf-8', default_filters=['escape'],
        imports=['from webhelpers.html import escape'])

    # Setup the SQLAlchemy database engine
    config['pylons.app_globals'].sa_default_engine = engine_from_config(config, 'sqlalchemy.default.', proxy=TimerProxy())
    init_model(config['pylons.app_globals'].sa_default_engine)
    
    config['pylons.errorware']['smtp_username'] = config.get('smtp_username')
    config['pylons.errorware']['smtp_password'] = config.get('smtp_password')
    config['pylons.errorware']['smtp_use_tls'] = config.get('smtp_use_tls')
    config['pylons.errorware']['smtp_port'] = config.get('smtp_port')
    
    # CONFIGURATION OPTIONS HERE (note: all config options will override
    # any Pylons config options)
    fs.setup_directories(config)
    setup_turbomail(config)
    
    return config