<commit_before>#!/usr/bin/python
##
# Main python module of the barbican client
##

from yapsy.PluginManager import PluginManager
from ConfigParser import ConfigParser
from argparse import ArgumentParser
from threading import Thread
from plugins.plugin_classes import MonitoringPlugin, FirewallPlugin
import logging
import os

plugin_manager = PluginManager()


def initializeBarbican(config_path):
    '''Read in config files and activate plugins'''
    config = ConfigParser()
    config.readfp(open(config_path))

    plugin_path = os.path.join(os.getcwd(), config.get("barbican_client",
                                                       "plugin_dir"))
    plugin_manager.setPluginInfoExtension("barbican-plugin")
    plugin_manager.setPluginPlaces([plugin_path])
    # Set up categories
    plugin_manager.setCategoriesFilter({
        "Monitoring": MonitoringPlugin,
        "Firewall": FirewallPlugin
        })
 
    plugin_manager.collectPlugins()

    for plugin_info in plugin_manager.getAllPlugins():
        print plugin_info, plugin_info.name

    print "Activating monitoring plugins"
    for plugin_info in plugin_manager.getPluginsOfCategory("Monitoring"):
        plugin_manager.activatePluginByName(plugin_info.name)

    for plugin_info in plugin_manager.getPluginsOfCategory("Monitoring"):
        plugin_info.plugin_object.set_hostname(config.get("barbican_client", "hostname"))
        plugin_info.plugin_object.set_config_file(config_path)

    print "Activating firewall"
    firewall_plugin = config.get("firewall_plugin")
    if firewall_plugin is not None:
        plugin_manager.activatePluginByName(firewall_plugin)
    else:
        plugin_manager.activatePluginByName("iptables plugin")

    return


def runBarbican():
    threads = []
    for plugin_info in plugin_manager.getAllPlugins():
        threads.append(Thread(target=plugin_info.plugin_object.run))
<commit_msg>Fix exception and missing arg to configparser.get()<commit_after>#!/usr/bin/python
##
# Main python module of the barbican client
##

from yapsy.PluginManager import PluginManager
from ConfigParser import ConfigParser, NoOptionError
from argparse import ArgumentParser
from threading import Thread
from plugins.plugin_classes import MonitoringPlugin, FirewallPlugin
import logging
import os

plugin_manager = PluginManager()


def initializeBarbican(config_path):
    '''Read in config files and activate plugins'''
    config = ConfigParser()
    config.readfp(open(config_path))

    plugin_path = os.path.join(os.getcwd(), config.get("barbican_client",
                                                       "plugin_dir"))
    plugin_manager.setPluginInfoExtension("barbican-plugin")
    plugin_manager.setPluginPlaces([plugin_path])
    # Set up categories
    plugin_manager.setCategoriesFilter({
        "Monitoring": MonitoringPlugin,
        "Firewall": FirewallPlugin
        })
 
    plugin_manager.collectPlugins()

    for plugin_info in plugin_manager.getAllPlugins():
        print plugin_info, plugin_info.name

    print "Activating monitoring plugins"
    for plugin_info in plugin_manager.getPluginsOfCategory("Monitoring"):
        plugin_manager.activatePluginByName(plugin_info.name)

    for plugin_info in plugin_manager.getPluginsOfCategory("Monitoring"):
        plugin_info.plugin_object.set_hostname(config.get("barbican_client", "hostname"))
        plugin_info.plugin_object.set_config_file(config_path)

    print "Activating firewall"
    try:
        firewall_plugin = config.get("barbican_client", "firewall_plugin")
        plugin_manager.activatePluginByName(firewall_plugin)
    except NoOptionError:
        plugin_manager.activatePluginByName("iptables plugin")

    return


def runBarbican():
    threads = []
    for plugin_info in plugin_manager.getAllPlugins():
        threads.append(Thread(target=plugin_info.plugin_object.run))

{'fraction_non_alphanumeric': 0.0821529745042493, 'fraction_numerical': 0.0, 'mean_word_length': 4.02457956015524, 'pattern_counts': {'":': 4, '<': 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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2711763', 'n_tokens_mistral': 1068, 'n_tokens_neox': 1046, 'n_words': 221}