コード例 #1
0
ファイル: NeuronLauncher.py プロジェクト: johnmelodyme/brain
 def start_neuron(cls, neuron, parameters_dict=dict()):
     """
     Execute each neuron from the received neuron_list.
     Replace parameter if exist in the received dict of parameters_dict
     :param neuron: Neuron object to run
     :param parameters_dict: dict of parameter to load in each neuron if expecting a parameter
     :return: List of the instantiated neurons (no errors detected)
     """
     if neuron.parameters is not None:
         try:
             neuron.parameters = cls._replace_brackets_by_loaded_parameter(neuron.parameters, parameters_dict)
         except NeuronParameterNotAvailable:
             Utils.print_danger("Missing parameter in neuron %s. Execution skipped" % neuron.name)
             return None
     try:
         instantiated_neuron = NeuronLauncher.launch_neuron(neuron)
     except NeuronExceptions as e:
         Utils.print_danger("ERROR: Fail to execute neuron '%s'. "
                            '%s' ". -> Execution skipped" % (neuron.name, e.message))
         return None
     return instantiated_neuron
コード例 #2
0
ファイル: NeuronLauncher.py プロジェクト: johnmelodyme/brain
 def _neuron_parameters_are_available_in_loaded_parameters(string_parameters, loaded_parameters):
     """
     Check that all parameters in brackets are available in the loaded_parameters dict
     
     E.g:
     string_parameters = "this is a {{ parameter1 }}"
     
     Will return true if the loaded_parameters looks like the following
     loaded_parameters { "parameter1": "a value"}        
     
     :param string_parameters: The string that contains one or more parameters in brace brackets
     :param loaded_parameters: Dict of parameter
     :return: True if all parameters in brackets have an existing key in loaded_parameters dict
     """
     list_parameters_with_brackets = Utils.find_all_matching_brackets(string_parameters)
     # remove brackets to keep only the parameter name
     for parameter_with_brackets in list_parameters_with_brackets:
         parameter = Utils.remove_spaces_in_brackets(parameter_with_brackets)
         parameter = parameter.replace("{{", "").replace("}}", "")
         if loaded_parameters is None or parameter not in loaded_parameters:
             Utils.print_danger("The parameter %s is not available in the order" % str(parameter))
             return False
     return True