def configure_logging(filename, disable_existing_loggers=None): """ Configure loggers. This is a wrapper around logging.config.fileConfig and logging.config.dictConfig. :param str filename: A logger configuration file to apply. :param bool disable_existing_loggers: Enforce a `disable_existing_loggers` setting. The default is `None` which means: - do *not* disable exising loggers if ini-style config (this is the opposite of the logging.config.fileConfig() default) - use value from config if dict-style config """ base, ext = os.path.splitext(filename) if ext == '.ini': # TODO: Should we even allow using fileConfig logging.config.fileConfig( filename, disable_existing_loggers=bool(disable_existing_loggers)) else: conf_dict = loader.read_config(filename) conf_dict.setdefault('version', 1) if disable_existing_loggers is None: disable_existing_loggers = conf_dict.setdefault( 'disable_existing_loggers', bool(disable_existing_loggers)) else: conf_dict['disable_existing_loggers'] = disable_existing_loggers logging.config.dictConfig(conf_dict)
def load_config(filepath=None): config_cls = CIMConfig() if filepath: config_cls.load_dict(read_config(filepath)) else: read(config_cls, 'cim') config_cls.validate() return config_cls
def load_ad_ldap_config(name='ad_ldap', filepath=None): config = ADLDAPConfig() if filepath: config.load_dict(read_config(filepath)) else: read(config, name) config.validate() return config
def load_config(filename=None): config_cls = StatsConfig() if filename: config_cls.load_dict(read_config(filename)) else: read(config_cls, CONFIG_BASENAME) config_cls.validate() return config_cls
def load_ad_ldap_config(name='ad_ldap', filepath=None): config = ADLDAPConfig() if filepath: config.load_dict(read_config(filepath)) else: read(config, name) config.validate() return config
def load_config(filepath=None): config_cls = CIMConfig() if filepath: config_cls.load_dict(read_config(filepath)) else: read(config_cls, 'cim') config_cls.validate() return config_cls
def load_config(filepath=None): config_cls = ExchangeConfig() if filepath: config_cls.load_dict(read_config(filepath)) else: read(config_cls, 'exchange') config_cls.validate() return config_cls
def load_config(filepath=None): """ Loads and validates the GPG data configuration. """ config_cls = GPGDataConfig() if filepath: config_cls.load_dict(read_config(filepath)) else: read(config_cls, 'gpg_data') config_cls.validate() return config_cls
def load_config(filepath=None): """Load config for this consumer.""" config_cls = SAPConsumerConfig() if filepath: config_cls.load_dict(read_config(filepath)) else: read(config_cls, 'consumer_sap') config_cls.validate() return config_cls
def load_config(filepath=None): """Load config for this consumer.""" config_cls = FPEConsumerConfig() if filepath: config_cls.load_dict(read_config(filepath)) else: read(config_cls, 'consumer_enforce_forward_policy') config_cls.validate() return config_cls
def _load_partial_config(cls, root_name, filepath): """ Try to load a given config into a config class `cls`. """ config = cls() if filepath: config.load_dict(read_config(filepath)) else: read(config, root_name) config.validate() return config
def _load_partial_config(cls, root_name, filepath): """ Try to load a given config into a config class `cls`. """ config = cls() if filepath: config.load_dict(read_config(filepath)) else: read(config, root_name) config.validate() return config
def load_config(filepath=None): """ Loads and validates the GPG data configuration. """ config_cls = GPGDataConfig() if filepath: config_cls.load_dict(read_config(filepath)) else: read(config_cls, 'gpg_data') config_cls.validate() return config_cls
def load_config(filepath=None): """Load config for this consumer.""" config_cls = FPEConsumerConfig() if filepath: config_cls.load_dict(read_config(filepath)) else: read(config_cls, 'consumer_enforce_forward_policy') config_cls.validate() return config_cls
def load_config(filepath=None): """Load config for this consumer.""" config_cls = FPEConsumerConfig() if filepath: config_cls.load_dict(read_config(filepath)) else: read(config_cls, 'consumer_affiliations') config_cls.validate() return config_cls
def load_config(filepath=None): """ """ config_cls = PasswordNotifierConfig() if filepath: config_cls.load_dict(read_config(filepath)) else: read(config_cls, 'password_notifier') config_cls.validate() return config_cls
def load_config(filepath=None): """ """ config_cls = PasswordGeneratorConfig() if filepath: config_cls.load_dict(read_config(filepath)) else: read(config_cls, 'password_generator') config_cls.validate() return config_cls
def load_config(filepath=None): """ """ config_cls = PasswordGeneratorConfig() if filepath: config_cls.load_dict(read_config(filepath)) else: read(config_cls, 'password_generator') config_cls.validate() return config_cls
def load_config(filepath=None): """ """ config_cls = PasswordNotifierConfig() if filepath: config_cls.load_dict(read_config(filepath)) else: read(config_cls, 'password_notifier') config_cls.validate() return config_cls
def load_config(filepath=None): u"""Load the config in filepath. defaults to event_publisher.json""" config_cls = AMQPClientPublisherConfig() if filepath: config_cls.load_dict(read_config(filepath)) else: read(config_cls, 'event_publisher') config_cls.validate() return config_cls
def load_amqp_client_config(celery_task, filepath=None): """ Loads the Cerebrum.config for the AMQPClient defaults to sys.prefix/etc/config/`celery_task`.json """ config = AMQPClientPublisherConfig() if filepath: config.load_dict(read_config(filepath)) else: read(config, celery_task) config.validate() return config
def main(): parser = argparse.ArgumentParser(description=__doc__) parser.add_argument('-c', '--commit', action='store_true', default=False, help="Do commit the changes to db") parser.add_argument('--config', action='store', default=None, help='Config file') parser.add_argument('types', action='store', nargs='+', help='The types to create (see config)') args = parser.parse_args() if args.config: conf = CreateOuGroupConfig(read_config(args.config)) else: conf = read(CreateOuGroupConfig(), 'create-ougroups') configs = {} for t in conf.types: configs[t.name] = t db = Factory.get('Database')(client_encoding='UTF-8') db.cl_init(change_program="create-ougroups") co = Factory.get('Constants')(db) for tp in args.types: if tp in configs: logger.info('Setting up groups for rule %s', tp) conf = configs[tp] aff, status = parse_aff(conf.aff, co) source = co.AuthoritativeSystem(conf.source) roots = conf.root recursion = co.VirtualGroupOURecursion(conf.recursion) members = co.VirtualGroupOUMembership(conf.members) perspective = co.OUPerspective(conf.perspective) spreads = map(co.Spread, conf.spreads) for root in roots: logger.info('Setting up root %s', root) setup_types(db, root, recursion, aff, status, source, members, perspective, conf.nametemplate, conf.descriptiontemplate, spreads, co) logger.info('Done setting up %s', tp) else: sys.exit(1) if args.commit: logger.info('Committing') db.commit() else: logger.info('Doing rollback') db.rollback()
def get_config(config_file=None, namespace=DEFAULT_LOGGING_CONFIG): """ Autoload a LoggingEnvironment config file. :param str config_file: Read the logging configuration from this file. :param str namespace: If no `config_file` is given, look for a config with this basename in the configuration directory. :return LoggingEnvironment: Returns a configuration object. """ config = LoggingEnvironment() if config_file: config.load_dict(loader.read_config(config_file)) else: loader.read(config, root_ns=namespace) return config
def get_config(config_file=None, namespace=DEFAULT_TEMPLATES_CONFIG): """ Autoload a TemplatesConfig config file. :param str config_file: Read the logging configuration from this file. :param str namespace: If no `config_file` is given, look for a config with this basename in the configuration directory. :return TemplatesConfig: Returns a configuration object. """ templates_config = TemplatesConfig() if config_file: templates_config.load_dict(loader.read_config(config_file)) else: loader.read(templates_config, root_ns=namespace) return templates_config
def get_config(config_file=None, namespace=DEFAULT_TEMPLATES_CONFIG): """ Autoload a TemplatesConfig config file. :param str config_file: Read the logging configuration from this file. :param str namespace: If no `config_file` is given, look for a config with this basename in the configuration directory. :return TemplatesConfig: Returns a configuration object. """ templates_config = TemplatesConfig() if config_file: templates_config.load_dict(loader.read_config(config_file)) else: loader.read(templates_config, root_ns=namespace) return templates_config
def load_config(filepath=None, consumer_name=None): u"""Load config. Load config from filepath or the config associated with consumer_name. Defaults to consumer_config.json :type filepath: str :param filepath: The filepath to load :type consumer_name: str :param consumer_name: Load <consumer_name>.json""" config_cls = AMQPClientConsumerConfig() if filepath: config_cls.load_dict(read_config(filepath)) elif consumer_name: read(config_cls, consumer_name) else: read(config_cls, 'consumer_config') config_cls.validate() return config_cls
def setup_logging(config, preset_name, loglevel, disable_existing=False): """ (re)configures logging. :param LoggerConfig config: A configuration that controls the loading of logger configuration. :param str preset_name: Which logger configuration to set up. :param int loglevel: A default loglevel to use with the default (stderr) handler, if no root handlers are applied through the logger configuration. :param bool disable_existing: If any and all existing logger configuration should be disabled. """ extensions = list(e for e in parsers.list_extensions() if e != 'ini') if not config.merge: extensions.append('ini') preset_files = [] if config.common_preset: common_preset = find_logging_preset(config.presets, config.common_preset, extensions=extensions) if common_preset: preset_files.append(common_preset) preset = find_logging_preset(config.presets, preset_name, extensions=extensions) if preset: preset_files.append(preset) elif config.require_preset: raise ValueError("no configuration '{0}' in '{1}'".format( preset_name, config.presets)) if preset_files and config.merge: # Merge configs and apply config_dict = merge_dict_config(*(loader.read_config(f) for f in preset_files)) config_dict['disable_existing_loggers'] |= disable_existing logging.config.dictConfig(config_dict) elif preset_files: # Apply each config in order for config_file in preset_files: configure_logging(config_file, disable_existing_loggers=disable_existing) # The disable_existing is only a default for the first config. # Remaining config files should use whatever is specified in the # file itself. disable_existing = None # if no other root handlers have been set up... logging.basicConfig(level=loglevel) if loglevel: logging.getLogger().setLevel(loglevel) logger.debug("Logging config {!r}".format(config)) for c in preset_files: logger.debug("Loaded logger config '{0}'".format(c))