<commit_before>from charms.reactive import when, when_not
from charms.reactive import set_state, remove_state
from charms.reactive.helpers import any_file_changed

from charmhelpers.core import hookenv

from jujubigdata.utils import DistConfig

from charms.layer.flume_base import Flume


@when('flume-base.installed')
@when_not('flume-sink.joined')
def waiting_for_flume_connection():
    hookenv.status_set('blocked', 'Waiting for connection to Flume Sink')


@when('flume-base.installed', 'flume-sink.joined')
@when_not('flume-sink.ready')
def waiting_for_flume_available(sink):  # pylint: disable=unused-argument
    hookenv.status_set('blocked', 'Waiting for Flume Sink')


@when('flume-base.installed', 'flume-sink.ready')
def configure_flume(sink):
    hookenv.status_set('maintenance', 'Configuring Flume')
    flume = Flume(DistConfig())
    flume.configure_flume({'agents': sink.agents()})
    if any_file_changed(flume.config_file):
        flume.restart()
    hookenv.status_set('active', 'Ready')
    set_state('flume-twitter.started')


@when('flume-twitter.started')
@when_not('flume-sink.ready')
def stop_flume():
    flume = Flume(DistConfig())
    flume.stop()
    remove_state('flume-twitter.started')<commit_msg>Refactors and fixes based on reviews<commit_after>from charms.reactive import when, when_not
from charms.reactive import set_state, remove_state
from charms.reactive.helpers import any_file_changed

from charmhelpers.core import hookenv

from charms.layer.apache_flume_base import Flume


@when('flume-base.installed')
@when_not('flume-sink.joined')
def waiting_for_flume_connection():
    hookenv.status_set('blocked', 'Waiting for connection to Flume Sink')


@when('flume-base.installed', 'flume-sink.joined')
@when_not('flume-sink.ready')
def waiting_for_flume_available(sink):  # pylint: disable=unused-argument
    hookenv.status_set('blocked', 'Waiting for Flume Sink')


@when('flume-base.installed', 'flume-sink.ready')
def configure_flume(sink):
    hookenv.status_set('maintenance', 'Configuring Flume')
    flume = Flume()
    flume.configure_flume({'agents': sink.agents()})
    if any_file_changed([flume.config_file]):
        flume.restart()
    hookenv.status_set('active', 'Ready')
    set_state('flume-syslog.started')


@when('flume-syslog.started')
@when_not('flume-sink.ready')
def stop_flume():
    flume = Flume()
    flume.stop()
    remove_state('flume-syslog.started')
{'fraction_non_alphanumeric': 0.1330861145447054, 'fraction_numerical': 0.0, 'mean_word_length': 5.7444444444444445, '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': '5415332', 'n_tokens_mistral': 868, 'n_tokens_neox': 838, 'n_words': 148}