# Path: lightbulb/core/operate.py
# def manage(module_name, configuration):
#     """
#     This function manages the module initialization and execution
#     Args:
#         module_name (class): The module class to be initiated
#         configuration (dict): The module options
#     Returns:
#        list: A list with the results and stats as tuples
#     """
# 
#     module = __import__(module_name)
#     classmembers = [classmodule for classmodule in inspect.getmembers(module, inspect.isclass)
#                     if classmodule[0] == 'Module' or classmodule[0] == 'Module_A'
#                     or classmodule[0] == 'Module_B']
#     if len(classmembers) == 1:
#         return  operate_learn(classmembers[0][1], configuration)
#     else:
#         if classmembers[0][0] == "Module_A":
#             return operate_diff(classmembers[0][1], configuration, classmembers[1][1], configuration)
#         else:
#             return operate_diff(classmembers[1][1], configuration, classmembers[0][1], configuration)
# 
# def operate_diff(module_class_A, configuration_A, module_class_B, configuration_B):
#     """
#     Initiates the execution of two modules in parallel
#     Args:
#         module_class_A (class): The module class to be initiated
#         configuration_A (dict): The module options
#         module_class_B (class): The module class to be initiated
#         configuration_B (dict): The module options
#     Returns:
#         None
#     """
#     object_a = None
#     object_b = None
#     shared_a = None
#     shared_b = None
#     target_a = None
#     target_b = None
#     target_a_pipe, target_b_pipe = Pipe()
#     result = []
#     shared_memory = [target_a_pipe, target_b_pipe, object_a, object_b, shared_a, shared_b, result]
# 
#     target_a = Thread(target=operate_diff_part,
#                       args=(module_class_A, configuration_A, shared_memory, 1))
#     target_a.setDaemon(True)
#     target_a.start()
#     target_b = Thread(target=operate_diff_part,
#                       args=(module_class_B, configuration_B, shared_memory, 2))
#     target_b.setDaemon(True)
#     target_b.start()
#     while True:
#         target_a.join(600)
#         if not target_a.isAlive():
#             target_a = None
#             break
#     print 'thread one finished'
#     # End Cross _check
#     target_b.join(0)
#     target_b = None
#     print 'thread two finished'
#     return  shared_memory[6]
# 
# def operate_learn(module, configuration):
#     """
#    Initiates the execution of a module
#    Args:
#        module (class): The module class to be initiated
#        configuration (dict): The module options
#    Returns:
#        list: A list with the results and stats as tuples
#    """
#     initmodule = module(configuration)
#     initmodule.learn()
#     name, bypass = initmodule.getresult()
#     return [(name, bypass)] + initmodule.stats()
# 
# Path: lightbulb/core/base.py
# def options_as_dictionary(meta):
#     """
#     Transforms a list of tuples to a dictionary
#     Args:
#         meta (list): A list ot option tuples
#     Retuns:
#         dict: A dictionary of options key - values
#     """
#     module_config = {}
#     for seltuple in meta:
#         module_config.update({seltuple[0]: seltuple[1]})
#     return  module_config
# 
# def importmodule(name):
#     try:
#        try:
#           mod = __import__(name)
#        except:
#           modfile, pathname, description = imp.find_module(name)
#           mod = imp.load_module(name, modfile, pathname, description)
#        components = name.split('.')
#        for comp in components[1:]:
#            mod = getattr(mod, comp)
#     except ImportError as error:
#        print error.__class__.__name__ + ": " + error.message
# 
#     return mod
# 
# def create_object(object_type, object_type_configuration, handler, handler_configuration):
#     object_mod = importmodule('lightbulb.core.modules.' + object_type.lower())
#     object_class = getattr(object_mod, object_type)
#     handler_mod = importmodule('lightbulb.core.utils.' + handler.lower())
#     handler_class = getattr(handler_mod, handler)
#     class Module(object_class):
#         def setup(self, configuration):
#             super(Module,self).setup(configuration)
#             self.handler = handler_class(handler_configuration)
#     return  Module


import logging
import sys
import os
import imp
import inspect
import platform as distplatform
from cliff.command import Command
from cliff.lister import Lister
from lightbulb.core.operate import manage, operate_diff, operate_learn
from lightbulb.core.base import options_as_dictionary, importmodule, create_object
from sys import platform
        global CONFIG
        """
        Sets an option value
        Args:
            parsed_args.set[0] (str): The requested option
            parsed_args.set[1] (str): The new value
        Returns:
            None
        """
        CONFIG[parsed_args.set[0]] =  (' '.join(parsed_args.set[1:])).strip()

        print "Option "+parsed_args.set[0]+' defined as '+(' '.join(parsed_args.set[1:])).strip()


class Back(Command):
    "Moves back to main menu view"

    log = logging.getLogger(__name__)


    def take_action(self, parsed_args):
        """
        Moves back to main menu view
        """
        global  CURRENT, META, HANDLER, MEMORY, CORE, TYPE
        print 'Back to main menu '
        if HANDLER:
            save_configuration = {x:CONFIG[x] for x in options_as_dictionary(META)}
            MEMORY[HANDLER] = {'TYPE':TYPE, 'CONFIG':save_configuration}
        if CORE:

# Path: lightbulb/core/operate.py
# def manage(module_name, configuration):
#     """
#     This function manages the module initialization and execution
#     Args:
#         module_name (class): The module class to be initiated
#         configuration (dict): The module options
#     Returns:
#        list: A list with the results and stats as tuples
#     """
# 
#     module = __import__(module_name)
#     classmembers = [classmodule for classmodule in inspect.getmembers(module, inspect.isclass)
#                     if classmodule[0] == 'Module' or classmodule[0] == 'Module_A'
#                     or classmodule[0] == 'Module_B']
#     if len(classmembers) == 1:
#         return  operate_learn(classmembers[0][1], configuration)
#     else:
#         if classmembers[0][0] == "Module_A":
#             return operate_diff(classmembers[0][1], configuration, classmembers[1][1], configuration)
#         else:
#             return operate_diff(classmembers[1][1], configuration, classmembers[0][1], configuration)
# 
# def operate_diff(module_class_A, configuration_A, module_class_B, configuration_B):
#     """
#     Initiates the execution of two modules in parallel
#     Args:
#         module_class_A (class): The module class to be initiated
#         configuration_A (dict): The module options
#         module_class_B (class): The module class to be initiated
#         configuration_B (dict): The module options
#     Returns:
#         None
#     """
#     object_a = None
#     object_b = None
#     shared_a = None
#     shared_b = None
#     target_a = None
#     target_b = None
#     target_a_pipe, target_b_pipe = Pipe()
#     result = []
#     shared_memory = [target_a_pipe, target_b_pipe, object_a, object_b, shared_a, shared_b, result]
# 
#     target_a = Thread(target=operate_diff_part,
#                       args=(module_class_A, configuration_A, shared_memory, 1))
#     target_a.setDaemon(True)
#     target_a.start()
#     target_b = Thread(target=operate_diff_part,
#                       args=(module_class_B, configuration_B, shared_memory, 2))
#     target_b.setDaemon(True)
#     target_b.start()
#     while True:
#         target_a.join(600)
#         if not target_a.isAlive():
#             target_a = None
#             break
#     print 'thread one finished'
#     # End Cross _check
#     target_b.join(0)
#     target_b = None
#     print 'thread two finished'
#     return  shared_memory[6]
# 
# def operate_learn(module, configuration):
#     """
#    Initiates the execution of a module
#    Args:
#        module (class): The module class to be initiated
#        configuration (dict): The module options
#    Returns:
#        list: A list with the results and stats as tuples
#    """
#     initmodule = module(configuration)
#     initmodule.learn()
#     name, bypass = initmodule.getresult()
#     return [(name, bypass)] + initmodule.stats()
# 
# Path: lightbulb/core/base.py
# def options_as_dictionary(meta):
#     """
#     Transforms a list of tuples to a dictionary
#     Args:
#         meta (list): A list ot option tuples
#     Retuns:
#         dict: A dictionary of options key - values
#     """
#     module_config = {}
#     for seltuple in meta:
#         module_config.update({seltuple[0]: seltuple[1]})
#     return  module_config
# 
# def importmodule(name):
#     try:
#        try:
#           mod = __import__(name)
#        except:
#           modfile, pathname, description = imp.find_module(name)
#           mod = imp.load_module(name, modfile, pathname, description)
#        components = name.split('.')
#        for comp in components[1:]:
#            mod = getattr(mod, comp)
#     except ImportError as error:
#        print error.__class__.__name__ + ": " + error.message
# 
#     return mod
# 
# def create_object(object_type, object_type_configuration, handler, handler_configuration):
#     object_mod = importmodule('lightbulb.core.modules.' + object_type.lower())
#     object_class = getattr(object_mod, object_type)
#     handler_mod = importmodule('lightbulb.core.utils.' + handler.lower())
#     handler_class = getattr(handler_mod, handler)
#     class Module(object_class):
#         def setup(self, configuration):
#             super(Module,self).setup(configuration)
#             self.handler = handler_class(handler_configuration)
#     return  Module


# Path: lightbulb/cli/use.py
import logging
import sys
import os
import imp
import inspect
import platform as distplatform
from cliff.command import Command
from cliff.lister import Lister
from lightbulb.core.operate import manage, operate_diff, operate_learn
from lightbulb.core.base import options_as_dictionary, importmodule, create_object
from sys import platform

        global CONFIG
        """
        Sets an option value
        Args:
            parsed_args.set[0] (str): The requested option
            parsed_args.set[1] (str): The new value
        Returns:
            None
        """
        CONFIG[parsed_args.set[0]] =  (' '.join(parsed_args.set[1:])).strip()

        print "Option "+parsed_args.set[0]+' defined as '+(' '.join(parsed_args.set[1:])).strip()


class Back(Command):
    "Moves back to main menu view"

    log = logging.getLogger(__name__)


    def take_action(self, parsed_args):
        """
        Moves back to main menu view
        """
        global  CURRENT, META, HANDLER, MEMORY, CORE, TYPE
        print 'Back to main menu '
        if HANDLER:
            save_configuration = {x:CONFIG[x] for x in options_as_dictionary(META)}
            MEMORY[HANDLER] = {'TYPE':TYPE, 'CONFIG':save_configuration}
        if CORE:

            save_configuration = {x:CONFIG[x] for x in options_as_dictionary(META)}