<commit_before>'''
Created on Nov 9, 2014

@author: fechnert
'''

import yaml
import logging
import features


class Configuration(dict):
    ''' Read and provide the yaml config '''

    def __init__(self, path):
        ''' Initialize the file '''
        with open(path, 'r') as f:
            self.update(yaml.load(f))


class Supervisor(object):
    ''' Guide the different features to do their work '''

    def __init__(self):
        ''' Initialize the Config '''
        self.config = Configuration('config.yml')

    def execute(self):
        for feature in self._import_features().values():
            try:
                feature.run()
            except NotImplementedError:
                logging.warn('Can\'t run Feature \'{}\''.format(feature.__class__.__name__))

    def _get_enabled_features(self):
        ''' Get all features which are enabled in config '''
        features = []
        for feature in self.config['features']:
            if self.config['features'][feature]['enable']:
                features.append(feature)
        return features

    def _import_features(self):
        ''' Import only the needed features '''
        feature_objects = {}
        for feature in self._get_enabled_features():
            feature_objects.update({
                feature: getattr(features, feature)(self.config['features'][feature])
            })
        return feature_objects<commit_msg>Add client and channel models<commit_after>'''
Created on Nov 9, 2014

@author: fechnert
'''

import yaml
import logging
import features


class Configuration(dict):
    ''' Read and provide the yaml config '''

    def __init__(self, path):
        ''' Initialize the file '''
        with open(path, 'r') as f:
            self.update(yaml.load(f))


class Supervisor(object):
    ''' Guide the different features to do their work '''

    def __init__(self):
        ''' Initialize the Config '''
        self.config = Configuration('config.yml')

    def execute(self):
        for feature in self._import_features().values():
            try:
                feature.run()
            except NotImplementedError:
                logging.warn('Can\'t run Feature \'{}\''.format(feature.__class__.__name__))

    def _get_enabled_features(self):
        ''' Get all features which are enabled in config '''
        features = []
        for feature in self.config['features']:
            if self.config['features'][feature]['enable']:
                features.append(feature)
        return features

    def _import_features(self):
        ''' Import only the needed features '''
        feature_objects = {}
        for feature in self._get_enabled_features():
            feature_objects.update({
                feature: getattr(features, feature)(self.config['features'][feature])
            })
        return feature_objects


class Client(object):
    ''' Represents the client '''

    def __init__(self, **kwargs):
        ''' Fill the object dynamically with client attributes got from telnet '''
        for key, value in kwargs.items():
            setattr(self, key, value)


class Channel(object):
    ''' Represents the Channel '''

    def __init__(self, **kwargs):
        ''' Fill the object dynamically with channel attributes got from telnet '''
        for key, value in kwargs.items():
            setattr(self, key, value)
{'fraction_non_alphanumeric': 0.11754229741763135, 'fraction_numerical': 0.0029682398337785693, 'mean_word_length': 2.4213197969543145, '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': '1170484', 'n_tokens_mistral': 873, 'n_tokens_neox': 830, 'n_words': 261}