<commit_before>import os
import yaml

from jinja2 import Template


class ConfigBase(object):

    """
    Base config class
    """

    def is_valid(self):
        return True


class RiemannConfig(ConfigBase):

    """
    Riemann Config object
    """

    def __init__(self, cfg):
        self._data = cfg

    @property
    def host(self):
        return self._data["host"]

    @property
    def port(self):
        return int(self._data["port"])


class AgentConfig(ConfigBase):

    """
    Config for setuping agent
    """

    def __init__(self, cfg):
        self._data = cfg

    @property
    def name(self):
        return self._data["name"]

    @property
    def module(self):
        return self._data["module"]


class Config(ConfigBase):

    """
    Config object
    """

    def __init__(self, cfg):
        self._data = cfg
        self.is_valid()

    def is_valid(self):
        checks = ([self.riemann.is_valid] +
                  list(map(lambda x: x.is_valid, self.agents)))
        return all([c() for c in checks])

    @property
    def riemann(self):
        return RiemannConfig(self._data["riemann"])

    @property
    def interval(self):
        return self._data["interval"]
<commit_msg>Fallback to default Riemann config<commit_after>import os
import yaml

from jinja2 import Template


class ConfigBase(object):

    """
    Base config class
    """

    def is_valid(self):
        return True


class RiemannConfig(ConfigBase):

    """
    Riemann Config object
    """

    def __init__(self, cfg):
        self._data = cfg

    @property
    def host(self):
        return self._data["host"]

    @property
    def port(self):
        return int(self._data["port"])

    @staticmethod
    def default():
        return RiemannConfig({"host": "localhost",
                              "port": 5555
                              })


class AgentConfig(ConfigBase):

    """
    Config for setuping agent
    """

    def __init__(self, cfg):
        self._data = cfg

    @property
    def name(self):
        return self._data["name"]

    @property
    def module(self):
        return self._data["module"]


class Config(ConfigBase):

    """
    Config object
    """

    def __init__(self, cfg):
        self._data = cfg
        self.is_valid()

    def is_valid(self):
        checks = ([self.riemann.is_valid] +
                  list(map(lambda x: x.is_valid, self.agents)))
        return all([c() for c in checks])

    @property
    def riemann(self):
        return RiemannConfig(self._data.get("riemann",
                                            RiemannConfig.default()))

    @property
    def interval(self):
        return self._data["interval"]

{'fraction_non_alphanumeric': 0.1157390342793955, 'fraction_numerical': 0.0022115739034279398, 'mean_word_length': 2.0155555555555558, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '606847', 'n_tokens_mistral': 834, 'n_tokens_neox': 759, 'n_words': 197}