def __init__(self, name=None, state_id=None, input_data_ports=None, output_data_ports=None, income=None, outcomes=None, path=None, filename=None, check_path=True, safe_init=True): State.__init__(self, name, state_id, input_data_ports, output_data_ports, income, outcomes, safe_init=safe_init) self._script = None self.script = Script(path, filename, parent=self) self.logger = log.get_logger(self.name) # here all persistent variables that should be available for the next state run should be stored self.persistent_variables = {}
def __init__(self, library_path=None, library_name=None, version=None, # library state specific attributes # the following are the container state specific attributes name=None, state_id=None, income=None, outcomes=None, input_data_port_runtime_values=None, use_runtime_value_input_data_ports=None, output_data_port_runtime_values=None, use_runtime_value_output_data_ports=None, allow_user_interaction=True, safe_init=True, skip_runtime_data_initialization=False): # this variable is set to true if the state initialization is finished! after initialization no change to the # library state is allowed any more self.initialized = False State.__init__(self, name, state_id, None, None, income, outcomes, safe_init=safe_init) self.library_path = library_path self.library_name = library_name self.version = version if global_config.get_config_value("RAISE_ERROR_ON_MISSING_LIBRARY_STATES", False): allow_user_interaction = False lib_os_path, new_library_path, new_library_name = \ library_manager.get_os_path_to_library(library_path, library_name, allow_user_interaction) self.lib_os_path = lib_os_path if library_path != new_library_path or library_name != new_library_name: self.library_name = new_library_name self.library_path = new_library_path # TODO this should trigger the marked_dirty of the state machine to become true logger.info("Changing information about location of library") logger.info("Old library name '{0}' was located at {1}".format(library_name, library_path)) logger.info("New library name '{0}' is located at {1}".format(new_library_name, new_library_path)) lib_version, state_copy = library_manager.get_library_state_copy_instance(self.lib_os_path) if not str(lib_version) == version and not str(lib_version) == "None": raise AttributeError("Library does not have the correct version!") self.state_copy = state_copy if safe_init: LibraryState._safe_init(self, name) else: LibraryState._unsafe_init(self, name) if not skip_runtime_data_initialization: # load_library_root_state_timer.stop(key) self._handle_runtime_values(input_data_port_runtime_values, use_runtime_value_input_data_ports, output_data_port_runtime_values, use_runtime_value_output_data_ports) else: self._input_data_port_runtime_values = input_data_port_runtime_values self._use_runtime_value_input_data_ports = use_runtime_value_input_data_ports self._output_data_port_runtime_values = output_data_port_runtime_values self._use_runtime_value_output_data_ports = use_runtime_value_output_data_ports self.initialized = True
def __init__( self, library_path=None, library_name=None, version=None, # library state specific attributes # the following are the container state specific attributes name=None, state_id=None, outcomes=None, input_data_port_runtime_values=None, use_runtime_value_input_data_ports=None, output_data_port_runtime_values=None, use_runtime_value_output_data_ports=None, allow_user_interaction=True): # this variable is set to true if the state initialization is finished! after initialization no change to the # library state is allowed any more self.initialized = False State.__init__(self, name, state_id, None, None, outcomes) self.library_path = library_path self.library_name = library_name self.version = version lib_os_path, new_library_path, new_library_name = \ library_manager.get_os_path_to_library(library_path, library_name, allow_user_interaction) self.lib_os_path = lib_os_path if library_path != new_library_path or library_name != new_library_name: self.library_name = new_library_name self.library_path = new_library_path # TODO this should trigger the marked_dirty of the state machine to become true logger.info("Changing information about location of library") logger.info("Old library name '{0}' was located at {1}".format( library_name, library_path)) logger.info("New library name '{0}' is located at {1}".format( new_library_name, new_library_path)) # key = load_library_root_state_timer.start() lib_version, state_copy = library_manager.get_library_state_copy_instance( self.lib_os_path) self.state_copy = state_copy # load_library_root_state_timer.stop(key) self.state_copy.parent = self if not str(lib_version) == version and not str(lib_version) == "None": raise AttributeError("Library does not have the correct version!") if name is None: self.name = self.state_copy.name # copy all ports and outcomes of self.state_copy to let the library state appear like the container state # this will also set the parent of all outcomes and data ports to self self.outcomes = self.state_copy.outcomes self.input_data_ports = self.state_copy.input_data_ports self.output_data_ports = self.state_copy.output_data_ports # handle input runtime values self.input_data_port_runtime_values = input_data_port_runtime_values self.use_runtime_value_input_data_ports = use_runtime_value_input_data_ports for data_port_id, data_port in self.input_data_ports.iteritems(): # Ensure that all input data ports have a runtime value if data_port_id not in self.input_data_port_runtime_values.iterkeys( ): self.input_data_port_runtime_values[ data_port_id] = data_port.default_value self.use_runtime_value_input_data_ports[data_port_id] = True # Ensure that str and unicode is correctly differentiated elif isinstance(self.input_data_port_runtime_values[data_port_id], basestring): try: self.input_data_port_runtime_values[ data_port_id] = type_helpers.convert_string_value_to_type_value( self.input_data_port_runtime_values[data_port_id], data_port.data_type) except AttributeError: # the parameter cannot be converted # this can be the case when the data type of port of the library state changed self.input_data_port_runtime_values[ data_port_id] = data_port.default_value self.use_runtime_value_input_data_ports[ data_port_id] = True self.marked_dirty = True # if there is a key existing in the runtime values but not in the input_data_ports we delete it for key in self.use_runtime_value_input_data_ports.keys(): if key not in self.input_data_ports.keys(): del self.use_runtime_value_input_data_ports[key] del self.input_data_port_runtime_values[key] # state machine cannot be marked dirty directly, as it does not exist yet self.marked_dirty = True # handle output runtime values self.output_data_port_runtime_values = output_data_port_runtime_values self.use_runtime_value_output_data_ports = use_runtime_value_output_data_ports for data_port_id, data_port in self.output_data_ports.iteritems(): # Ensure that all output data ports have a runtime value if data_port_id not in self.output_data_port_runtime_values.iterkeys( ): self.output_data_port_runtime_values[ data_port_id] = data_port.default_value self.use_runtime_value_output_data_ports[data_port_id] = True # Ensure that str and unicode is correctly differentiated elif isinstance(self.output_data_port_runtime_values[data_port_id], basestring): try: self.output_data_port_runtime_values[data_port_id] = \ type_helpers.convert_string_value_to_type_value( self.output_data_port_runtime_values[data_port_id], data_port.data_type) except AttributeError: # the parameter cannot be converted # this can be the case when the data type of port of the library state changed self.output_data_port_runtime_values[ data_port_id] = data_port.default_value self.use_runtime_value_output_data_ports[ data_port_id] = True self.marked_dirty = True # if there is a key existing in the runtime values but not in the output_data_ports we delete it for key in self.use_runtime_value_output_data_ports.keys(): if key not in self.output_data_ports.keys(): del self.use_runtime_value_output_data_ports[key] del self.output_data_port_runtime_values[key] # state machine cannot be marked dirty directly, as it does not exist yet self.marked_dirty = True self.initialized = True