Example #1
0
def load_environment(global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config``
    object
    """
    # 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='hewwolord', paths=paths)

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

    # Create the Genshi TemplateLoader
    config['pylons.app_globals'].genshi_loader = TemplateLoader(
        paths['templates'], auto_reload=True)

    # Setup the SQLAlchemy database engine
    if 'sqlalchemy.module' in config:
        config['sqlalchemy.module'] = __import__(config['sqlalchemy.module'])

    engine = engine_from_config(config, 'sqlalchemy.')
        
    try:
        import coev

        flagdict = {
            'coev.debug.lib.coev': coev.CDF_COEV,
            'coev.debug.lib.coev.dump': coev.CDF_COEV_DUMP,
            'coev.debug.lib.colock': coev.CDF_COLOCK,
            'coev.debug.lib.colock.dump': coev.CDF_COLOCK_DUMP,
            'coev.debug.lib.nbuf': coev.CDF_NBUF,
            'coev.debug.lib.nbuf.dump': coev.CDF_NBUF_DUMP,
            'coev.debug.lib.runq.dump': coev.CDF_RUNQ_DUMP,
            'coev.debug.lib.stack': coev.CDF_STACK,
            'coev.debug.lib.stack.dump': coev.CDF_STACK_DUMP }
        
        lib_debug_flags = 0
        for f in flagdict:
            if asbool(config.get(f, False)):
                lib_debug_flags |= flagdict[f]

        coev.setdebug(  asbool(config.get('coev.debug.module', False)),
                        lib_debug_flags )
                        
        import thread
        thread.stack_size(int(config.get('coev.stack.size', 2 * 1024 * 1024)))
    except ImportError:
        pass    
    
    mcservers = aslist(config['memcache.servers'])
    mcdebug = asbool(config['memcache.debug'])
    init_model(engine, mcservers, mcdebug)
Example #2
0
        return rv

    def __call__(self, environ, start_response):
        if environ.get("PATH_INFO") == self.path:
            text = self.index(environ)
            start_response("200 OK", [("content-type", "text/plain"), ("content-length", str(len(text)))])
            return [text]
        return self.app(environ, start_response)


if __name__ == "__main__":

    sys.setcheckinterval(10000000)
    logging.basicConfig(stream=sys.stderr, level=logging.DEBUG)
    coev.setdebug(False, 0)
    sys.excepthook = sys.__excepthook__

    def dump_environ(environ, start_response):
        """
        Application which simply dumps the current environment
        variables out as a plain text response.
        Ripped out of paste.wsgilib for the following reasonos:
        sick of patching '0' in content-length every single time.
        """
        output = []
        keys = environ.keys()
        keys.sort()
        for k in keys:
            v = str(environ[k]).replace("\n", "\n    ")
            output.append("%s: %s\n" % (k, v))