13.1. The core

Subpackages

config

class rafcon.core.config.Config(logger_object=None)

Bases: rafcon.core.config.ObservableConfig

Class to hold and load the global state machine configurations.

keys_requiring_restart = ()
load(config_file=None, path=None)

Loads the configuration from a specific file

Parameters
  • config_file – the name of the config file

  • path – the path to the config file

class rafcon.core.config.ObservableConfig(default_config_string, logger_object=None)

Bases: yaml_configuration.config.DefaultConfig, rafcon.design_patterns.observer.observable.Observable

as_dict()

Returns the configuration as dict

Returns

A copy of the whole configuration as dict

Return type

dict

get_config_value(key, default=None)

Overwrites the default behavior of the get_config_value method of the DefaultConfig base class It supports the

Parameters
  • key – the key to the configuration value

  • default – what to return if the key is not found

Returns

The value for the given key, if the key was found. Otherwise the default value

is_config_loaded_from_file()

Returns if the configuration values were loaded from a custom file (and are thus not simply initiated from the default config any more).

Returns

a flag indicating if the config was loaded from a file

property keys
keys_requiring_restart = {}
keys_requiring_state_machine_refresh = {}
set_config_value(**kwargs)

Get a specific configuration value

Parameters
  • key – the key to the configuration value

  • value – The new value to be set for the given key

custom_exceptions

exception rafcon.core.custom_exceptions.LibraryNotFoundException(message)

Bases: Exception

exception rafcon.core.custom_exceptions.LibraryNotFoundSkipException(message)

Bases: Exception

exception rafcon.core.custom_exceptions.RecoveryModeException(message, do_delete_item)

Bases: ValueError

property do_delete_item

Property for the do_delete_item field

constants (in rafcon.core)

global_variable_manager

id_generator

rafcon.core.id_generator.generate_data_flow_id()
rafcon.core.id_generator.generate_data_port_id(used_data_port_ids)

Create a new and unique data port id

Parameters

used_data_port_ids (list) – Handed list of ids already in use

Return type

int

Returns

data_port_id

rafcon.core.id_generator.generate_outcome_id(used_outcome_ids)
rafcon.core.id_generator.generate_script_id()
rafcon.core.id_generator.generate_semantic_data_key(used_semantic_keys)

Create a new and unique semantic data key

Parameters

used_semantic_keys (list) – Handed list of keys already in use

Return type

str

Returns

semantic_data_id

rafcon.core.id_generator.generate_state_machine_id()

Generates an id for a state machine. It simply uses a global counter that is increased each time. :return: a new state machine id

rafcon.core.id_generator.generate_state_name_id()

Generates an id for a state

It simply uses a global counter that is increased each time. It is intended for the name of a new state.

Returns

a new state machine id

rafcon.core.id_generator.generate_transition_id()
rafcon.core.id_generator.global_variable_id_generator(size=10, chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ')

Create a new and unique global variable id

Generates an id for a global variable. It randomly samples from random ascii uppercase letters size times and concatenates them. If the id already exists it draws a new one.

Parameters
  • size – the length of the generated keys

  • chars – the set of characters a sample draws from

rafcon.core.id_generator.history_item_id_generator()
rafcon.core.id_generator.run_id_generator()
rafcon.core.id_generator.state_id_generator(size=6, chars='ABCDEFGHIJKLMNOPQRSTUVWXYZ', used_state_ids=None)

Create a new and unique state id

Generates an id for a state. It randomly samples from random ascii uppercase letters size times and concatenates them. If the id already exists it draws a new one.

Parameters
  • size – the length of the generated keys

  • chars – the set of characters a sample draws from

  • used_state_ids (list) – Handed list of ids already in use

Return type

str

Returns

new_state_id

interface

rafcon.core.interface.create_folder_cmd_line(query, default_name=None, default_path=None)

Queries the user for a path to be created

Parameters
  • query (str) – Query that asks the user for a specific folder path to be created

  • default_name (str) – Default name of the folder to be created

  • default_path (str) – Path in which the folder is created if the user doesn’t specify a path

Returns

Input path from the user or default_path if nothing is specified or None if directory could ne be created

Return type

str

rafcon.core.interface.create_folder_func(query, default_name=None, default_path=None)

Queries the user for a path to be created

Parameters
  • query (str) – Query that asks the user for a specific folder path to be created

  • default_name (str) – Default name of the folder to be created

  • default_path (str) – Path in which the folder is created if the user doesn’t specify a path

Returns

Input path from the user or default_path if nothing is specified or None if directory could ne be created

Return type

str

rafcon.core.interface.open_folder_cmd_line(query, default_path=None)

Queries the user for a path to open

Parameters
  • query (str) – Query that asks the user for a specific folder path to be opened

  • default_path (str) – Path to use if the user doesn’t specify a path

Returns

Input path from the user or default_path if nothing is specified or None if path does not exist

Return type

str

rafcon.core.interface.open_folder_func(query, default_path=None)

Queries the user for a path to open

Parameters
  • query (str) – Query that asks the user for a specific folder path to be opened

  • default_path (str) – Path to use if the user doesn’t specify a path

Returns

Input path from the user or default_path if nothing is specified or None if path does not exist

Return type

str

rafcon.core.interface.save_folder_cmd_line(query, default_name=None, default_path=None)

Queries the user for a path or file to be saved into

The folder or file has not to be created already and will not be created by this function. The parent directory of folder and file has to exist otherwise the function will return None.

Parameters
  • query (str) – Query that asks the user for a specific folder/file path to be created

  • default_name (str) – Default name of the folder to be created

  • default_path (str) – Path in which the folder is created if the user doesn’t specify a path

Returns

Input path from the user or default_path if nothing is specified and None if directory does not exist

Return type

str

rafcon.core.interface.show_notice(notice, custom_buttons=None)

Shows a notice on the console that has to be acknowledged

Parameters

notice (str) – Notice to show to the user

rafcon.core.interface.show_notice_func(notice, custom_buttons=None)

Shows a notice on the console that has to be acknowledged

Parameters

notice (str) – Notice to show to the user

library_manager

script

class rafcon.core.script.Script(path=None, filename=None, parent=None)

Bases: rafcon.design_patterns.observer.observable.Observable, yaml.YAMLObject

A class for representing the script file for all execution states in a state machine.

It inherits from Observable to make a change of its fields observable.

Variables
  • path – the path where the script resides

  • filename – the full name of the script file

  • _compiled_module – the compiled module

  • _script_id – the id of the script

  • check_path – a flag to indicate if the path should be checked for existence

compile_module()

Builds a temporary module from the script file

Raises

exceptions.IOError – if the compilation of the script module failed

property compiled_module

Return the compiled module

execute(state, inputs=None, outputs=None, backward_execution=False)

Execute the user ‘execute’ function specified in the script

Parameters
  • state (ExecutionState) – the state belonging to the execute function, refers to ‘self’

  • inputs (dict) – the input data of the script

  • outputs (dict) – the output data of the script

  • backward_execution (bool) – Flag whether to run the script in backwards mode

Returns

Return value of the execute script

Return type

str | int

property filename

Property for the _filename field

property parent

Property for the _parent field

property path
property script
set_script_without_compilation(script_text)

singleton (in rafcon.core)

state_machine

class rafcon.core.state_machine.StateMachine(root_state=None, version=None, creation_time=None, state_machine_id=None)

Bases: rafcon.design_patterns.observer.observable.Observable, jsonconversion.jsonobject.JSONObject, rafcon.utils.hashable.Hashable

A class for to organizing all main components of a state machine

It inherits from Observable to make a change of its fields observable.

Variables
  • StateMachine.state_machine_id (int) – the id of the state machine

  • StateMachine.root_state (rafcon.core.states.state) – the root state of the state machine

  • StateMachine.base_path (str) – the path, where to save the state machine

acquire_modification_lock(blocking=True)

Acquires the modification lock of the state machine

This must be used for all methods, that perform any modifications on the state machine

Parameters

blocking (bool) – When True, block until the lock is unlocked, then set it to locked

Returns

True if lock was acquired, False else

Return type

bool

change_root_state_type(**kwargs)
clear_execution_histories(**kwargs)
destroy_execution_histories()
property execution_histories
property file_system_path

Property for the _file_system_path field

classmethod from_dict(dictionary, state_machine_id=None)

Abstract method

This method must be implemented by the deriving classes. It must return an object of type cls, created from the parameters defined in dictionary. The type of cls is the type of the class the method is called on.

Parameters

dictionary (dict) – A Python dict with all parameters needed for creating an object of type cls

Returns

An instance of cls

Return type

cls

get_last_execution_log_filename()
get_modification_lock()
get_state_by_path(path, as_check=False)
join()

Wait for root state to finish execution

property marked_dirty

Property for the _marked_dirty field

modification_lock(blocking=True)

Get modification lock in with() statement

Parameters

blocking (bool) – When True, block until the lock is unlocked, then set it to locked

release_modification_lock()

Releases the acquired state machine modification lock.

property root_state

Property for the _root_state field

start()

Starts the execution of the root state.

state_machine_id = None
static state_machine_to_dict(state_machine)
property supports_saving_state_names
to_dict()

Abstract method

This method must be implemented by the deriving classes. It must return a Python dict with all parameters of self, which are needed to create a copy of self.

Returns

A Python dict with all needed parameters of self

Return type

dict

update_hash(obj_hash)

Should be implemented by derived classes to update the hash with their data fields

Parameters

obj_hash – The hash object (see Python hashlib)

version = None

state_machine_manager