def merge(base, other): if isinstance(other, basestring): cherrypy.engine.autoreload.files.add(other) for section, value_map in reprconf.as_dict(other).items(): if not isinstance(value_map, dict): raise ValueError("Application config must include section headers, but the config you tried to merge doesn't have any sections. Wrap your config in another dict with paths as section headers, for example: {'/': config}.") base.setdefault(section, {}).update(value_map)
def setup_server(configfile): if not exists(configfile): raise ConfigurationError(_("Could not find configuration file: %s") % configfile) cherrypy.config.update({ 'tools.sessions.on': True, 'tools.nestedvars.on': True }) app_config = as_dict(configfile) _global = app_config.pop('global', {}) _environ = _global.setdefault('server.environment', 'development') if _environ != 'development': _global['environment'] = _environ cherrypy.config.update(_global) static_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'static') app_config.update({'/static': { 'tools.staticdir.on': True, 'tools.staticdir.dir': static_dir }}) app_config.update({'/favicon.ico': { 'tools.staticfile.on': True, 'tools.staticfile.filename': static_dir + "/images/favicon.ico" }}) app_config.update({'/LICENSE.txt': { 'tools.staticfile.on': True, 'tools.staticfile.filename': static_dir + "/../../doc/LICENSE.txt" }}) # import profiler while makes profile decorator available as __builtins__ from openerp import profiler from openerp.controllers.root import Root app = cherrypy.tree.mount(Root(), '/', app_config) import pkg_resources from openerp.widgets import register_resource_directory static = pkg_resources.resource_filename("openerp", "static") register_resource_directory(app, "openerp", static) # initialize the rpc session host = app.config['openerp'].get('host') port = app.config['openerp'].get('port') protocol = app.config['openerp'].get('protocol') from openerp import rpc rpc.initialize(host, port, protocol, storage=CPSessionWrapper())
def merge(base, other): """Merge one app config (from a dict, file, or filename) into another. If the given config is a filename, it will be appended to the list of files to monitor for "autoreload" changes. """ if isinstance(other, basestring): cherrypy.engine.autoreload.files.add(other) for section, value_map in reprconf.as_dict(other).items(): if not isinstance(value_map, dict): raise ValueError( "Application config must include section headers, but the config you tried to merge doesn't have any sections. Wrap your config in another dict with paths as section headers, for example: {'/': config}." ) base.setdefault(section, {}).update(value_map)
def __setup(self): config = as_dict(str(self.global_config_path)) try: local_config = as_dict(str(self.local_config_path)) self.__deep_update(config, local_config) except IOError: pass self.update(config) for key, subkey in self.ABSOLUTE_PATHS: self.__absolutize(key, subkey, self._base_dir) # Manually set tools.staticdir.root from static_dir if '/' not in self: self['/'] = {} self['/']['tools.staticdir.root'] = self._static_dir # Absolutize any relative filename paths for cherrypy. for key, subdict in self.items(): if key[0] == '/': subkey = 'tools.staticfile.filename' if subkey in subdict: self.__absolutize(key, subkey, self._static_dir) return config
def merge(base, other): """Merge one app config (from a dict, file, or filename) into another. If the given config is a filename, it will be appended to the list of files to monitor for "autoreload" changes. """ if isinstance(other, basestring): cherrypy.engine.autoreload.files.add(other) # Load other into base for section, value_map in reprconf.as_dict(other).items(): if not isinstance(value_map, dict): raise ValueError( "Application config must include section headers, but the " "config you tried to merge doesn't have any sections. " "Wrap your config in another dict with paths as section " "headers, for example: {'/': config}.") base.setdefault(section, {}).update(value_map)
def start(): parser = OptionParser(version="%s" % (openobject.release.version)) parser.add_option("-c", "--config", metavar="FILE", dest="config", help="configuration file", default=get_config_file()) parser.add_option("-a", "--address", help="host address, overrides server.socket_host") parser.add_option("-p", "--port", help="port number, overrides server.socket_port") parser.add_option("--no-static", dest="static", action="store_false", default=True, help="Disables serving static files through CherryPy") options, args = parser.parse_args(sys.argv) if not os.path.exists(options.config): raise ConfigurationError( _("Could not find configuration file: %s") % options.config) app_config = as_dict(options.config) openobject.configure(app_config) if options.static: openobject.enable_static_paths() if options.address: cherrypy.config['server.socket_host'] = options.address if options.port: try: cherrypy.config['server.socket_port'] = int(options.port) except: pass configure_babel() cherrypy.engine.start() cherrypy.engine.block()
def configure(config=None, enable_static=False, logging_configuration=None, loggers=None, **overrides): """ Configures OpenERP Web Client. Takes a CherryPy configuration with two sections (``global`` and ``openerp-web``) :param config: a configuration file path, a configuration file or a configuration dict (anything which can be used by cherrypy's ``as_dict``, really). If none is provided, the web client will go through its automatic configuration discovery process (see :func:`openobject.config.find_file`) :type config: ``str | < read :: () -> str > | dict | None`` :param enable_static: configure CherryPy to handle the distribution of static resources by itself (via static tools) :type enable_static: ``bool`` :param logging_configuration: the path to a ``logging`` configuration file, or a ``logging`` configuration file-like object, if specified and there is already a logging configuration file path in ``config``, will replace the value in ``config`` :type logging_configuration: ``str | < readline :: () -> str >`` :param loggers: mapping of loggers to logging levels, lighter configuration method than a full-blown configuration file cf :func:`openobject.config.configure_logging` for exact signature :type loggers: ``{str: (int|str)}`` :param overrides: additional configuration information, has the same structure as normal CherryPy configuration dicts, merged into CherryPy's configuration *after* ``config``. Generally used when ``config`` is a file path or a file-like object, in order to provide or override settings without needing to parse the configuration file from outside this function. """ openobject.config.configure_cherrypy() if not config: configuration = openobject.config.find_file() elif isinstance(config, basestring): configuration = os.path.expanduser( os.path.expandvars(config)) if not os.path.isfile(configuration): raise openobject.config.ConfigurationError( "The file '%s' could not be found " "or is not a valid file path" % config) else: configuration = config config_dict = as_dict(configuration) cherrypy.config.update( BASE_GLOBAL) cherrypy.config.update( config_dict.pop('global', {})) cherrypy.config.update( overrides.pop('global', {})) application.merge({'openerp-web': BASE_APP}) application.merge(config_dict) application.merge(overrides) openobject.config.configure_logging( logging_config=logging_configuration or application.config['openerp-web'].get('logging.config.file'), loggers=loggers) openobject.config.configure_babel() if enable_static: enable_static_paths()