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
def __init__(self, configfile=None): # Initialise the configuration self.load_config(configfile) # Initialise the template enginge. self.templates = rdw_templating.TemplateManager() # Initialise the plugins self.plugins = rdw_plugin.PluginManager(self.cfg) # Initialise the application cwd = os.path.abspath(os.path.dirname(__file__)) config = { b'/': { 'tools.authform.on': True, 'tools.i18n.on': True, 'tools.encode.on': True, 'tools.encode.encoding': 'utf-8', 'tools.gzip.on': True, 'tools.sessions.on': True, }, b'/favicon.ico': { 'tools.authform.on': False, 'tools.staticfile.on': True, 'tools.staticfile.filename': os.path.join(cwd, b'static', b'favicon.ico'), }, b'/login': { 'tools.authform.on': False, }, b'/static': { 'tools.staticdir.on': True, 'tools.staticdir.root': cwd, 'tools.staticdir.dir': "static", 'tools.authform.on': False, }, } self._setup_favicon(config) self._setup_header_logo(config) self._setup_session_storage(config) Application.__init__(self, root=Root(self), config=config) # Activate every loaded plugin self.plugins.run(lambda x: self.activate_plugin(x)) # create user manager self.userdb = UserManager(self)
def __init__(self, configfile=None): # Initialise the configuration self.load_config(configfile) # Initialise the template engine. self.templates = rdw_templating.TemplateManager() # Initialise the plugins self.plugins = rdw_plugin.PluginManager(self.cfg) # Initialise the application config = { native_str('/'): { 'tools.authform.on': True, 'tools.i18n.on': True, 'tools.i18n.default': 'en_US', 'tools.i18n.mo_dir': self._localedirs(), 'tools.i18n.domain': 'messages', 'tools.encode.on': True, 'tools.encode.encoding': 'utf-8', 'tools.gzip.on': True, 'tools.sessions.on': True, 'error_page.default': self.error_page, 'request.error_response': self.error_response, }, } # To work around the new behaviour in CherryPy >= 5.5.0, force usage of # ISO-8859-1 encoding for URL. This avoid any conversion of the # URL into UTF-8. if PY3 and LooseVersion(cherrypy.__version__) >= LooseVersion("5.5.0"): config[native_str('/')]["request.uri_encoding"] = "ISO-8859-1" self._setup_session_storage(config) Application.__init__(self, root=Root(self), config=config) # Activate every loaded plugin self.plugins.run(lambda x: self.activate_plugin(x)) # create user manager self.userdb = UserManager(self) # Start deamon plugins self._start_deamons()
def __init__(self, configFile=None): # Initialise config self.load_config(configFile) # Initialise template engine self.templates = bkw_templating.TemplateMgr() # Initialise plugins self.plugins = bkw_plugins.PluginsMgr(self.cfg) # Initialise application config = { native_str('/'): { 'tools.authform.on': True, 'tools.i18n.on': True, 'tools.encode.on': True, 'tools.encode.encoding': 'utf-8', 'tools.gzip.on': True, 'tools.sessions.on': True, 'error_page.default': self.error_page, } } # To work around the new behaviour in CherryPy >= 5.5.0, force usage of # ISO-8859-1 encoding for URL. This avoid any conversion of the # URL into UTF-8. if PY3 and cherrypy.__version__ >= "5.5.0": config[native_str('/')]["request.uri_encoding"] = "ISO-8859-1" self._setup_session_storage(config) Application.__init__(self, root=BkwebRoot(self), config=config) # Activate loaded plugins self.plugins.run(lambda x: self.activate_plugin(x)) # create user manager self.userdb = UserManager(self) # Start deamon plugin self._start_deamons()
def __init__(self, cfg={}): self.cfg = {k.lower(): v for k, v in cfg.items()} # Initialise the template engine. self.templates = rdw_templating.TemplateManager() # Get some config session_path = self.cfg.get("sessiondir", None) # Initialise the application config = { native_str('/'): { 'tools.authform.on': True, 'tools.i18n.on': True, 'tools.i18n.default': 'en_US', 'tools.i18n.mo_dir': pkg_resources.resource_filename( 'rdiffweb', 'locales'), # @UndefinedVariable 'tools.i18n.domain': 'messages', 'tools.encode.on': True, 'tools.encode.encoding': 'utf-8', 'tools.gzip.on': True, 'tools.sessions.on': True, 'tools.proxy.on': CP_PROXY, 'error_page.default': self.error_page, 'request.error_response': self.error_response, 'tools.sessions.storage_type': 'file' if session_path else 'ram', 'tools.sessions.storage_path': session_path, }, } # To work around the new behaviour in CherryPy >= 5.5.0, force usage of # ISO-8859-1 encoding for URL. This avoid any conversion of the # URL into UTF-8. if PY3 and LooseVersion(cherrypy.__version__) >= LooseVersion("5.5.0"): config[native_str('/')]["request.uri_encoding"] = "ISO-8859-1" # Initialize the application Application.__init__(self, root=Root(), config=config) # Register favicon.ico self.root.favicon_ico = static(self._favicon) # Register header_logo if self._header_logo: self.root.header_logo = static(self._header_logo) # Define TEMP env if self._tempdir: os.environ["TMPDIR"] = self._tempdir # create user manager self.userdb = UserManager(self)
def gather(): return Application.__call__(self, env, handler) return self.profiler.run(gather)
def __init__(self, app, path): Application.__init__(self, app.root, app.script_name, app.config) self.profiler = profiler.ProfileAggregator(path)
def gather(): return Application.__call__(self, env, handler)
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, ".")
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()