def mount(self, script_name, app, conf=None): webapp = None try: _conf = self.conf.copy() _cpconfig.merge(_conf, self.conf) webapp = cherrypy.tree.mount(app, script_name, _conf) self.bus.log("Mounted web application '%s' at '%s'" % (app.__class__, script_name or '/')) except: cherrypy.log("Failed mounting '%s' at '%s'" % (app.__class__, script_name or '/'), traceback=True) else: if webapp: self.bus.publish("mounted-webapp", webapp)
def add (self, path, handler, config = None): stripped_path = path.strip ('/') path_list = stripped_path.split ('/') if stripped_path else [] if self.handler_exists (path_list): raise AttributeError ('Path "{0}" is busy in "{1}"'.format (path, self.owner.name)) if config: if not hasattr (handler, '_cp_config'): handler._cp_config = {} _cpconfig.merge (handler._cp_config, config) handler._cp_mount_path = '/' + stripped_path if not path_list: self.root = handler else: setattr (self.find_owner (path_list [0:-1]), path_list [-1], handler) cherrypy.log.error ('{} mounted on "{}" in "{}"'.format (type (handler).__name__, path, self.owner.name), 'TREE')
def add(self, path, handler, config=None): stripped_path = path.strip('/') path_list = stripped_path.split('/') if stripped_path else [] if self._handler_exists(path_list): raise AttributeError('Path `%s` is busy' % path) if config: if not hasattr(handler, '_cp_config'): handler._cp_config = {} _cpconfig.merge(handler._cp_config, config) handler._cp_mount_path = '/' + stripped_path if not path_list: self.root = handler else: setattr(self._find_owner(path_list[0:-1]), path_list[-1], handler) cherrypy.log.error('%s mounted on `%s`' % (type(handler).__name__, path), 'TREE')
def get_applications (mode, basename): import controllers _cpconfig.merge ( config, pkg_resources.resource_filename (__package__, '__config__/%s.conf' % mode) ) conf = config.get ('main', {}) db.auto_config (config, __package__, '', 'db') #alchemy.wrap (__package__) app = cherrybase.Application ( name = __package__, vhosts = conf.get ('vhosts', '.'.join ((__package__, basename))), config = config, routes = ( ('/', controllers.Example (), None), ) ) return app
def add(self, path, handler, config=None): stripped_path = path.strip('/') path_list = stripped_path.split('/') if stripped_path else [] if self.handler_exists(path_list): raise AttributeError('Path "{0}" is busy in "{1}"'.format( path, self.owner.name)) if config: if not hasattr(handler, '_cp_config'): handler._cp_config = {} _cpconfig.merge(handler._cp_config, config) handler._cp_mount_path = '/' + stripped_path if not path_list: self.root = handler else: setattr(self.find_owner(path_list[0:-1]), path_list[-1], handler) cherrypy.log.error( '{} mounted on "{}" in "{}"'.format( type(handler).__name__, path, self.owner.name), 'TREE')
def get_applications(mode, basename): from cherrypy import _cpconfig from cherrybase import Application, db, orm from cherrybase.db.drivers.pgsql import PgSql from cherrybase.orm.drivers.alchemy import SqlAlchemy import pkg_resources # Читаем конфиг config = {} _cpconfig.merge( config, pkg_resources.resource_filename(__package__, 'config/{}.conf'.format(mode))) def get_conf_global(entry, default): return config.get('/', {}).get(entry, default) # Добавляем в каталог пулов БД нашу db.catalog['test'] = PgSql(host=get_conf_global('db_host', '127.0.0.1'), port=get_conf_global('db_port', '5432'), dbname=get_conf_global('db_name', ''), user=get_conf_global('db_user', 'postgres'), password=get_conf_global( 'db_password', 'secret')) orm.catalog['test'] = SqlAlchemy('test') engine = cherrypy.engine engine.task_manager.add('test', test_bg_job, 60) # Возвращаем экземпляр приложения или список экземпляров return Application(name='test', vhosts=[ vhost + basename if vhost[-1] == '.' else vhost for vhost in _vhosts ], config=config, routes=(('/', controllers.RootController(), None), ))
def merge(self, config): """Merge the given config into self.config.""" _cpconfig.merge(self.config, config) # Handle namespaces specified in config. self.namespaces(self.config.get('/', {}))
def merge(self, config): """Merge the given config into self.config.""" _cpconfig.merge(self.config, config) # Handle namespaces specified in config. self.namespaces(self.config.get("/", {}))
def merge(self, config): _cpconfig.merge(self.config, config) self.namespaces(self.config.get('/', {}))
def merge(self, config): """Merge the given config into self.config.""" _cpconfig.merge(self.config, config) # Handle namespaces specified in config. _cpconfig._call_namespaces(self.config.get("/", {}), self.namespaces)
def merge(self, config): """Merge the given config into self.config.""" _cpconfig.merge(self.config, config) self.namespaces(self.config.get('/', {}))
def merge(self, config:Dict(str, Dyn)): """Merge the given config into self.config.""" _cpconfig.merge(self.config, config) # Handle namespaces specified in config. self.namespaces(self.config.get("/", {}))