Esempio n. 1
0
    def install_application(self):
        """Install application and its components from the configuration."""
        index = self.srvconfig.index

        # First instantiate non-view extensions.
        if getattr(self.config, 'extensions', None):
            for ext in self.config.extensions:
                name = ext._internal_name
                if not self.silent:
                    cherrypy.log("INFO: instantiating extension %s" % name)
                module_name, class_name = ext.object.rsplit(".", 1)
                module = __import__(module_name, globals(), locals(), [class_name])
                obj = getattr(module, class_name)(self, ext)
                self.extensions[name] = obj

        # Then instantiate views and mount them to cherrypy. If the view is
        # designated as the index, create it as an application, profiled one
        # if server profiling was requested. Otherwise just mount it as a
        # normal server content object. Force tracebacks off for everything.
        for view in self.config.views:
            name = view._internal_name
            path = "/%s" % self.appname + ((name != index and "/%s" % name) or "")
            if not self.silent:
                cherrypy.log("INFO: loading %s into %s" % (name, path))
            module_name, class_name = view.object.rsplit(".", 1)
            module = __import__(module_name, globals(), locals(), [class_name])
            obj = getattr(module, class_name)(self, view, path)
            app = Application(obj, path, {"/": {"request.show_tracebacks": False}})
            if getattr(self.srvconfig, 'profile', False):
                profdir = "%s/profile" % self.statedir
                if not os.path.exists(profdir):
                    os.makedirs(profdir)
                app = ProfiledApp(app, profdir)
            cherrypy.tree.mount(app)
            self.views[name] = obj
Esempio n. 2
0
from WMCore.REST.Main import RESTDaemon
from WMCore.REST.Test import fake_authz_key_file
from WMCore.Configuration import Configuration
from cherrypy import Application
import os

def dummy():
    return ""

import os

authz_key = fake_authz_key_file()
cfg = Configuration()
main = cfg.section_('main')
main.application = 'test'
main.silent = True
main.index = 'top'
main.authz_defaults = { 'role': None, 'group': None, 'site': None }
main.section_('tools').section_('cms_auth').key_file = authz_key.name
app = cfg.section_('test')
app.admin = '*****@*****.**'
app.description = app.title = 'Test'
views = cfg.section_('views')
top = views.section_('top')
top.object = os.path.abspath(__file__).rsplit("/", 1)[-1].split(".")[0] + ".Test"

ProfiledApp(Application(dummy, "/", {"/": {}}), ".")
Logger()
RESTMain(cfg, ".")
RESTDaemon(cfg, ".")
Esempio n. 3
0
        return big_s


cherrypy.tree.mount(Test())

if __name__ == '__main__':
    import sys, os
    cherrypy.config.update({
        'server.environment': 'production',
        'server.log_to_screen': LOG_TO_SCREEN,
    })
    if len(sys.argv) > 1 and sys.argv[1] == 'normal':
        print 'Using regular cherrypy WSGI server'
        cherrypy.config.update({
            'server.socket_port': PORT,
        })
        cherrypy.server.start()
    else:
        print "Using eventful's WSGI wrapping example"
        cherrypy.config.update({
            'server.protocol_version': 'HTTP/1.1',
        })
        app = Application(Test())
        app.merge({
            '/static': {
                'tools.staticdir.on': True,
                'tools.staticdir.dir': os.path.abspath('./static'),
            }
        })
        WSGIApplication(app, PORT).run()