<commit_before>import uuid
from abusehelper.core import bot
from abusehelper.core.config import *

class Clusters(object):
    def __init__(self):
        self.names = dict()
        self.nodes = dict()

    def add(self, name, node):
        self.names.setdefault(name, set()).add(node)
        self.nodes.setdefault(node, set()).add(name)

    def __iter__(self):
        for name, nodes in self.names.items():
            nodes = set(node for node in nodes if len(self.nodes.get(node, ())) == 1)
            yield name, nodes

class DotBot(bot.Bot):
    bot_name = None
    ini_file = None
    ini_section = None

    runtime_config = bot.Param("runtime configuration module")
    startup_config = bot.Param("startup configuration module",
                               default=None)
    node_per_service = bot.BoolParam()
    show_attributes = bot.BoolParam()
    cluster_by_type = bot.BoolParam()
    cluster_by_name = bot.BoolParam()

    def run(self):
        print "digraph G {"
        print "node [ shape=box, style=filled, color=lightgrey ];"

        if self.startup_config is not None:
            services = set()
            for config in load_configs(self.startup_config):
                startup = getattr(config, "startup", None)
                if startup is None:
                    continue
                attrs = dict(startup())
                services.add(attrs.get("bot_name", None))
            services.discard(None)
            missing = lambda x: x not in services
        else:
            missing = lambda x: False

        types = Clusters()
        names = Clusters()
        type_names = dict()

        for config in load_configs(self.runtime_config):
            config_runtime = getattr(config, "runtime", lambda x: [])

            sessions = set()
            for container in config_runtime():
                for session in container:
                    sessions.add(session)

            for session in sessions:
                conf = dict(session.conf)
                path = session.path
                src = conf.pop("src_room", None)
                dst = conf.pop("dst_room", None)

                node = None<commit_msg>runtime2dot: Changes to config reading to reflect changes made in r625. Fixes issue 48.<commit_after>import uuid
from abusehelper.core import bot
from abusehelper.core.config import *

class Clusters(object):
    def __init__(self):
        self.names = dict()
        self.nodes = dict()

    def add(self, name, node):
        self.names.setdefault(name, set()).add(node)
        self.nodes.setdefault(node, set()).add(name)

    def __iter__(self):
        for name, nodes in self.names.items():
            nodes = set(node for node in nodes if len(self.nodes.get(node, ())) == 1)
            yield name, nodes

class DotBot(bot.Bot):
    bot_name = None
    ini_file = None
    ini_section = None

    runtime_config = bot.Param("runtime configuration module")
    startup_config = bot.Param("startup configuration module",
                               default=None)
    node_per_service = bot.BoolParam()
    show_attributes = bot.BoolParam()
    cluster_by_type = bot.BoolParam()
    cluster_by_name = bot.BoolParam()

    def run(self):
        print "digraph G {"
        print "node [ shape=box, style=filled, color=lightgrey ];"

        if self.startup_config is not None:
            services = set()
            for config in load_configs(self.startup_config):
                startup = getattr(config, "startup", None)
                if startup is None:
                    continue
                attrs = dict(startup())
                services.add(attrs.get("bot_name", None))
            services.discard(None)
            missing = lambda x: x not in services
        else:
            missing = lambda x: False

        types = Clusters()
        names = Clusters()
        type_names = dict()

        module = load_module(self.runtime_config, False)
        configs = getattr(module, "configs", None)
        if not callable(configs):
            raise ImportError("no callable configs defined")

        for config in configs():
            sessions = set()
            for session in flatten(config):
                sessions.add(session)

            for session in sessions:
                conf = dict(session.conf)
                path = session.path
                src = conf.pop("src_room", None)
                dst = conf.pop("dst_room", None)

                node = None
{'fraction_non_alphanumeric': 0.09897458760588497, 'fraction_numerical': 0.0017833259028087382, 'mean_word_length': 1.9212239583333333, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2117474', 'n_tokens_mistral': 1245, 'n_tokens_neox': 1197, 'n_words': 334}