def set_config(self, config_filename, conf, error): super(WSGIApp, self).set_config(config_filename, conf, error) conf = configobj.ConfigObj( conf, configspec=configobj.ConfigObj(self.ConfigSpec)) config.validate(config_filename, conf, error) self.as_root = conf['application']['as_root'] self.app_title = unicode(conf['application']['title'], 'utf-8') self.custom_css = conf['application']['custom_css'] self.application_path = conf['application']['path'] # mail configuration mail_config = conf['mail'] self.mail_sender = self._create_mail_sender(mail_config) self.default_sender_email = mail_config['default_sender'] # assets manager configuration self.assets_manager = SimpleAssetsManager( conf['assetsmanager']['basedir'], self.name, **conf['assetsmanager']) # search_engine engine configuration self.search_engine = SearchEngine(**conf['search']) # other self.security = SecurityManager(conf['application']['crypto_key']) self.debug = conf['application']['debug'] self.default_locale = i18n.Locale( conf['locale']['major'], conf['locale']['minor']) self.auth_cfg = {'dbauth': conf['dbauth'], 'oauth': conf['oauth'], 'ldapauth': conf['ldapauth']} self.tpl_cfg = conf['application']['templates'] self.activity_monitor = conf['application'].get('activity_monitor', '')
def set_config(self, config_filename, conf, error): super(WSGIApp, self).set_config(config_filename, conf, error) conf = configobj.ConfigObj( conf, configspec=configobj.ConfigObj(self.ConfigSpec), interpolation='Template') config.validate(config_filename, conf, error) self._services = services.ServicesRepository( config_filename, error, conf ) self.as_root = conf['application']['as_root'] self.app_title = unicode(conf['application']['title'], 'utf-8') self.custom_css = conf['application']['custom_css'] self.application_path = conf['application']['path'] # search_engine engine configuration self.search_engine = SearchEngine(**conf['search']) # other self.security = SecurityManager(conf['application']['crypto_key']) self.debug = conf['application']['debug'] self.default_locale = i18n.Locale( conf['locale']['major'], conf['locale']['minor']) tpl_cfg = conf['application']['templates'] pub_cfg = { 'disclaimer': conf['application']['disclaimer'].decode('utf-8'), 'banner': conf['application']['banner'].decode('utf-8'), 'favicon': conf['application']['favicon'].decode('utf-8') } self.app_cfg = { 'authentication': conf['authentication'], 'tpl_cfg': tpl_cfg, 'pub_cfg': pub_cfg } self.activity_monitor = conf['application']['activity_monitor']
def _validate_config(self, conf, config_filename, error): """ Validates the INI configuration of the application :param conf: The parsed ConfigObj object :param config_filename: The config filepath :returns: """ base_conf = configobj.ConfigObj(conf, configspec=configobj.ConfigObj( self.APPLICATION_SPEC)) config.validate(config_filename, base_conf, error) # Complete application config spec with search engine spec search_engine_factory = self.load_entry_point( 'eureka.search_engine', base_conf['search_engine']['type']) self.APPLICATION_SPEC['search_engine'].update( search_engine_factory.SPEC) # Revalidate the entire config and initialize the application conf = configobj.ConfigObj(conf, configspec=configobj.ConfigObj( self.APPLICATION_SPEC)) config.validate(config_filename, conf, error) return dict(conf), search_engine_factory
def read_config(self, components, conf_filename, conf, error): spec = {comp.get_id(): comp.config_spec for comp in components} spec = configobj.ConfigObj({self.conf_section: spec}) components_conf = configobj.ConfigObj(conf_filename, configspec=spec, interpolation='Template') components_conf.merge(conf) config.validate(conf_filename, components_conf, error) return components_conf[self.conf_section]
def set_config(self, config_filename, conf, error): """Read the set of allowed hosts from the configuration file In: - ``config_filename`` -- the path to the configuration file - ``conf`` -- the ``ConfigObj`` object, created from the configuration file - ``error`` -- the function to call in case of configuration errors """ conf = configobj.ConfigObj(conf, configspec=configobj.ConfigObj(self.spec)) config.validate(config_filename, conf, error) self.allow_hosts = conf['allow_hosts']
def read_application_options(cfgfile, error, default=None): """Read the configuration file for the application In: - ``cfgfile`` -- path to an application configuration file - ``error`` -- the function to call in case of configuration errors - ``default`` -- optional default values Return: - a ``ConfigObj`` of the application parameters """ spec = configobj.ConfigObj(default or {}) spec.merge(application_options_spec) apps = ', '.join( '"%s"' % entry.name for entry in pkg_resources.iter_entry_points('nagare.applications')) spec.merge({'application': {'app': 'option(%s)' % (apps + ', ""')}}) choices = ', '.join( '"%s"' % entry.name for entry in pkg_resources.iter_entry_points('nagare.sessions')) spec.merge( {'sessions': { 'type': 'option(%s, default="")' % (choices + ', ""') }}) conf = configobj.ConfigObj(cfgfile, configspec=spec, interpolation='Template' if default else None) config.validate(cfgfile, conf, error) # The database sub-sections inherit from the database section spec['database']['__many__'].merge( dict( uri='string(default=%s)' % str(conf['database']['uri']), metadata='string(default=%s)' % str(conf['database']['metadata']), debug='boolean(default=%s)' % str(conf['database']['debug']), )) conf = configobj.ConfigObj(cfgfile, configspec=spec, interpolation='Template' if default else None) config.validate(cfgfile, conf, error) if not conf['sessions']['type']: del conf['sessions']['type'] return conf
def set_config(self, config_filename, conf, error): """Read the value of the ``as_root`` parameter and keeps the list of all the launched applications In: - ``config_filename`` -- the path to the configuration file - ``config`` -- the ``ConfigObj`` object, created from the configuration file - ``error`` -- the function to call in case of configuration errors """ conf = configobj.ConfigObj(conf, configspec=configobj.ConfigObj(application_spec)) config.validate(config_filename, conf, error) self.as_root = conf['application']['as_root'] self.application_url = conf['application']['name'] super(WSGIApp, self).set_config(config_filename, conf, error)
def set_config(self, config_filename, conf, error): super(WSGIApp, self).set_config(config_filename, conf, error) conf = configobj.ConfigObj( conf, configspec=configobj.ConfigObj(self.ConfigSpec), interpolation='Template') config.validate(config_filename, conf, error) self._services = services.ServicesRepository( config_filename, error, conf ) self.card_extensions = services.CardExtensions( config_filename, error, conf ) self.as_root = conf['application']['as_root'] self.app_title = unicode(conf['application']['title'], 'utf-8') self.app_name = conf['application']['name'] self.theme = conf['application']['theme'] self.application_path = conf['application']['path'] # search_engine engine configuration self.search_engine = SearchEngine(**conf['search']) self._services.register('search_engine', self.search_engine) Card.update_schema(self.card_extensions) # Make assets_manager available to kansha-admin commands self.assets_manager = self._services['assets_manager'] # other self.security = SecurityManager(conf['application']['crypto_key']) self.debug = conf['application']['debug'] self.default_locale = i18n.Locale( conf['locale']['major'], conf['locale']['minor']) pub_cfg = { 'disclaimer': conf['application']['disclaimer'].decode('utf-8'), 'banner': conf['application']['banner'].decode('utf-8'), 'favicon': conf['application']['favicon'].decode('utf-8') } self.app_config = { 'authentication': conf['authentication'], 'pub_cfg': pub_cfg } self.activity_monitor = conf['application']['activity_monitor']
def _validate_config(self, conf, config_filename, error): """ Validates the INI configuration of the application :param conf: The parsed ConfigObj object :param config_filename: The config filepath :returns: """ base_conf = configobj.ConfigObj(conf, configspec=configobj.ConfigObj(self.APPLICATION_SPEC)) config.validate(config_filename, base_conf, error) # Complete application config spec with search engine spec search_engine_factory = self.load_entry_point("eureka.search_engine", base_conf["search_engine"]["type"]) self.APPLICATION_SPEC["search_engine"].update(search_engine_factory.SPEC) # Revalidate the entire config and initialize the application conf = configobj.ConfigObj(conf, configspec=configobj.ConfigObj(self.APPLICATION_SPEC)) config.validate(config_filename, conf, error) return dict(conf), search_engine_factory
def read_publisher_options(parser, options): """Read the configuration file for the publisher This configuration file is given with the ``-c``or ``--config`` option In: - ``parser`` -- the ``optparse.OptParser`` object used to parse the configuration file - ``options`` -- options in the command line Return: - a ``ConfigObj`` with the publisher parameters """ if options.conf and not os.path.isfile(options.conf): parser.error('Configuration file "%s" doesn\'t exist' % options.conf) configspec = configobj.ConfigObj(publisher_options_spec) if options.conf: configspec.merge({'here': 'string(default="%s")' % os.path.abspath(os.path.dirname(options.conf))}) choices = ', '. join('"%s"' % entry.name for entry in pkg_resources.iter_entry_points('nagare.publishers')) configspec.merge({'publisher': {'type': 'option(%s, default="standalone")' % choices}}) choices = ', '. join('"%s"' % entry.name for entry in pkg_resources.iter_entry_points('nagare.sessions')) configspec.merge({'sessions': {'type': 'option(%s, default="standalone")' % choices}}) conf = configobj.ConfigObj(options.conf, configspec=configspec, interpolation='Template') config.validate(options.conf, conf, parser.error) # The options in the command line overwrite the parameters read into the configuration file for name, section, key in ( ('host', 'publisher', 'host'), ('port', 'publisher', 'port'), ('debug', 'publisher', 'debug'), ('reload', 'reloader', 'activated') ): option = getattr(options, name) if option is not None: conf[section][key] = option return conf
def set_config(self, filename, conf, error): """Read the configuration parameters In: - ``filename`` -- the path to the configuration file - ``conf`` -- the ``ConfigObj`` object, created from the configuration file - ``error`` -- the function to call in case of configuration errors """ conf = {k: v for k, v in conf.iteritems() if k in self.spec} conf = configobj.ConfigObj(conf, configspec=self.spec) config.validate(filename, conf, error) self.states_history = conf['states_history'] self.security_cookie_name = conf['security_cookie_name'] pickler = reference.load_object(conf['pickler'])[0] unpickler = reference.load_object(conf['unpickler'])[0] serializer = reference.load_object(conf['serializer'])[0] self.serializer = serializer(pickler, unpickler) return conf
def _validate_conf(self, filename, conf, error): """Validate the configuration read from the publisher configuration file In: - ``filename`` -- the path to the configuration file - ``conf`` -- the ``ConfigObj`` object, created from the configuration file - ``error`` -- the function to call in case of configuration errors Return: - the tuple: - hostname to listen to - port to listen to - conf object """ conf = {k: v for k, v in conf.iteritems() if k in self.spec} conf = configobj.ConfigObj(conf, configspec=self.spec, interpolation='Template') config.validate(filename, conf, error) conf = {k: v for k, v in conf.iteritems() if v is not None} return conf.pop('host'), conf.pop('port'), conf
def _validate_conf(self, filename, conf, error): """Validate the configuration read from the publisher configuration file In: - ``filename`` -- the path to the configuration file - ``conf`` -- the ``ConfigObj`` object, created from the configuration file - ``error`` -- the function to call in case of configuration errors Return: - the tuple: - hostname to listen to - port to listen to - conf object """ conf = dict([(k, v) for (k, v) in conf.items() if k in self.spec]) conf = configobj.ConfigObj(conf, configspec=self.spec, interpolation="Template") config.validate(filename, conf, error) conf = dict([(k, v) for (k, v) in conf.items() if v is not None]) return (conf.pop("host"), conf.pop("port"), conf)
def set_config(self, config_filename, conf, error): """Process the configuration file In: - ``config_filename`` -- the path to the configuration file - ``config`` -- the ``ConfigObj`` object, created from the configuration file - ``error`` -- the function to call in case of configuration errors """ conf = configobj.ConfigObj(conf, configspec=configobj.ConfigObj(WSGIApp.spec)) config.validate(config_filename, conf, error) self.allow_extensions = conf['navigator']['allow_extensions'] self.nagare_sources = conf['navigator']['nagare_sources'] self.editor_config = dict([(k, str(v).lower() if isinstance(v, bool) else v) for (k, v) in conf['editor'].items()]) # Create and configure the security manager # ----------------------------------------- self.security = reference.load_object(conf['security']['manager'])[0]() self.security.set_config(config_filename, conf['security'], error) super(WSGIApp, self).set_config(config_filename, conf, error)
def read_application_options(cfgfile, error, default={}): """Read the configuration file for the application In: - ``cfgfile`` -- path to an application configuration file - ``error`` -- the function to call in case of configuration errors - ``default`` -- optional default values Return: - a ``ConfigObj`` of the application parameters """ if default: default["name"] = 'string(default="%s")' % configobj.ConfigObj(cfgfile)["application"]["name"] spec = configobj.ConfigObj(default) spec.merge(application_options_spec) choices = ", ".join(['"%s"' % entry.name for entry in pkg_resources.iter_entry_points("nagare.sessions")]) spec.merge({"sessions": {"type": 'option(%s, default="")' % (choices + ', ""')}}) conf = configobj.ConfigObj(cfgfile, configspec=spec, interpolation="Template" if default else None) config.validate(cfgfile, conf, error) # The database sub-sections inherit from the database section spec["database"]["__many__"].merge( dict( uri="string(default=%s)" % str(conf["database"]["uri"]), metadata="string(default=%s)" % str(conf["database"]["metadata"]), debug="boolean(default=%s)" % str(conf["database"]["debug"]), ) ) conf = configobj.ConfigObj(cfgfile, configspec=spec, interpolation="Template" if default else None) config.validate(cfgfile, conf, error) if not conf["sessions"]["type"]: del conf["sessions"]["type"] return conf
def set_config(self, config_filename, conf, error): super(WSGIApp, self).set_config(config_filename, conf, error) conf = configobj.ConfigObj(conf, configspec=configobj.ConfigObj( self.ConfigSpec), interpolation='Template') config.validate(config_filename, conf, error) self._services = services.ServicesRepository(config_filename, error, conf) self.as_root = conf['application']['as_root'] self.app_title = unicode(conf['application']['title'], 'utf-8') self.theme = conf['application']['theme'] self.application_path = conf['application']['path'] # search_engine engine configuration self.search_engine = SearchEngine(**conf['search']) # other self.security = SecurityManager(conf['application']['crypto_key']) self.debug = conf['application']['debug'] self.default_locale = i18n.Locale(conf['locale']['major'], conf['locale']['minor']) tpl_cfg = conf['application']['templates'] pub_cfg = { 'disclaimer': conf['application']['disclaimer'].decode('utf-8'), 'banner': conf['application']['banner'].decode('utf-8'), 'favicon': conf['application']['favicon'].decode('utf-8') } self.app_cfg = { 'authentication': conf['authentication'], 'tpl_cfg': tpl_cfg, 'pub_cfg': pub_cfg } self.activity_monitor = conf['application']['activity_monitor']
def read_application_options(cfgfile, error, default={}): """Read the configuration file for the application In: - ``cfgfile`` -- path to an application configuration file - ``error`` -- the function to call in case of configuration errors - ``default`` -- optional default values Return: - a ``ConfigObj`` of the application parameters """ if default: default['name'] = 'string(default="%s")' % configobj.ConfigObj(cfgfile)['application']['name'] spec = configobj.ConfigObj(default) spec.merge(application_options_spec) choices = ', '. join(['"%s"' % entry.name for entry in pkg_resources.iter_entry_points('nagare.sessions')]) spec.merge({ 'sessions' : { 'type' : 'option(%s, default="")' % (choices + ', ""') } }) conf = configobj.ConfigObj(cfgfile, configspec=spec, interpolation='Template' if default else None) config.validate(cfgfile, conf, error) # The database sub-sections inherit from the database section spec['database']['__many__'].merge(dict( uri = 'string(default=%s)' % str(conf['database']['uri']), metadata = 'string(default=%s)' % str(conf['database']['metadata']), debug = 'boolean(default=%s)' % str(conf['database']['debug']), )) conf = configobj.ConfigObj(cfgfile, configspec=spec, interpolation='Template' if default else None) config.validate(cfgfile, conf, error) if not conf['sessions']['type']: del conf['sessions']['type'] return conf