def find_loader(path_or_stream, parser_or_type=None, is_path_=False): """ Find out config parser object appropriate to load from a file of given path or file/file-like object. :param path_or_stream: Configuration file path or file / file-like object :param parser_or_type: Forced configuration parser type or parser object :param is_path_: True if given `path_or_stream` is a file path :return: Config parser instance or None """ if anyconfig.backends.is_parser(parser_or_type): return parser_or_type (psr, err) = anyconfig.backends.find_parser(path_or_stream, parser_or_type, is_path_=is_path_) if err: LOGGER.error(err) if psr is None: if parser_or_type is None: LOGGER.warning("No parser (type) was given!") else: LOGGER.warning("Parser %s was not found!", str(parser_or_type)) return None LOGGER.debug("Using config parser: %r [%s]", psr, psr.type()) return psr() # TBD: Passing initialization arguments.
def find_loader(path_or_stream, forced_type=None, is_path_=None): """ Find out config parser object appropriate to load from a file of given path or file/file-like object. :param path_or_stream: Configuration file path or file / file-like object :param forced_type: Forced configuration parser type :param is_path_: True if given `path_or_stream` is a file path :return: Config parser instance or None """ (psr, err) = anyconfig.backends.find_parser(path_or_stream, forced_type, is_path_=is_path_) if psr is None: LOGGER.error(err) return None LOGGER.debug("Using config parser of type: %s", psr.type()) return psr() # TBD: Passing initialization arguments.
def find_loader(config_path, forced_type=None): """ :param config_path: Configuration file path :param forced_type: Forced configuration parser type :return: Parser-inherited class object """ if forced_type is not None: cparser = anyconfig.backends.find_by_type(forced_type) if not cparser: LOGGER.error("No parser found for given type: %s", forced_type) return None else: cparser = anyconfig.backends.find_by_file(config_path) if not cparser: LOGGER.error("No parser found for given file: %s", config_path) return None LOGGER.debug("Using config parser of type: %s", cparser.type()) return cparser