Storage: storage

storage (in rafcon.core.storage)

Helper functions to store a statemachine in the local file system and load it from there

rafcon.core.storage.storage.FILE_NAME_META_DATA = 'meta_data.json'

File names for various purposes

rafcon.core.storage.storage.clean_path(base_path)

This function cleans a file system path in terms of removing all not allowed characters of each path element. A path element is an element of a path between the path separator of the operating system.

Parameters

base_path – the path to be cleaned

Returns

the clean path

rafcon.core.storage.storage.clean_path_element(text, max_length=None, separator='_')

Replace characters that conflict with a free OS choice when in a file system path.

Parameters
  • text – the string to be cleaned

  • max_length – the maximum length of the output string

  • separator – the separator used for rafcon.core.storage.storage.limit_text_max_length

Returns

rafcon.core.storage.storage.clean_path_from_deprecated_naming(base_path)

Checks if the base path includes deprecated characters/format and returns corrected version

The state machine folder name should be according the universal RAFCON path format. In case the state machine path is inside a mounted library_root_path also the library_path has to have this format. The library path is a partial path of the state machine path. This rules are followed to always provide secure paths for RAFCON and all operating systems.

Parameters

base_path

Returns

cleaned base_path

Return type

str

rafcon.core.storage.storage.find_library_dependencies_via_grep(library_root_path, library_path=None, library_name=None)

Find the dependencies of a library via grep

Parameters
  • library_root_path (str) – the library root path

  • library_path (str) – the library path

  • library_name (str) – the library name

:rtype list(str) :return: library dependency paths

rafcon.core.storage.storage.get_core_data_path(state_path)
rafcon.core.storage.storage.get_meta_data_path(state_path)
rafcon.core.storage.storage.get_storage_id_for_state(state)

Calculates the storage id of a state. This ID can be used for generating the file path for a state.

Parameters

state (rafcon.core.states.state.State) – state the storage_id should is composed for

rafcon.core.storage.storage.limit_text_max_length(text, max_length, separator='_')

Limits the length of a string. The returned string will be the first max_length/2 characters of the input string plus a separator plus the last max_length/2 characters of the input string.

Parameters
  • text – the text to be limited

  • max_length – the maximum length of the output string

  • separator – the separator between the first “max_length”/2 characters of the input string and the last “max_length/2” characters of the input string

Returns

the shortened input string

rafcon.core.storage.storage.limit_text_to_be_path_element(text, max_length=None, separator='_')

Replace characters that are not in the valid character set of RAFCON.

Parameters
  • text – the string to be cleaned

  • max_length – the maximum length of the output string

  • separator – the separator used for rafcon.core.storage.storage.limit_text_max_length

Returns

rafcon.core.storage.storage.load_data_file(path_of_file)

Loads the content of a file by using json.load.

Parameters

path_of_file – the path of the file to load

Returns

the file content as a string

Raises

exceptions.ValueError – if the file was not found

rafcon.core.storage.storage.load_state_recursively(parent, state_path=None, dirty_states=[])

Recursively loads the state

It calls this method on each sub-state of a container state.

Parameters
  • parent – the root state of the last load call to which the loaded state will be added

  • state_path – the path on the filesystem where to find the meta file for the state

  • dirty_states – a dict of states which changed during loading

Returns

rafcon.core.storage.storage.reconnect_data_flow(state_machine)
rafcon.core.storage.storage.remove_obsolete_folders(states, path)

Removes obsolete state machine folders

This function removes all folders in the file system folder path that do not belong to the states given by states.

Parameters
  • states (list) – the states that should reside in this very folder

  • path (str) – the file system path to be checked for valid folders

rafcon.core.storage.storage.save_script_file_for_state_and_source_path(state, state_path_full, as_copy=False)

Saves the script file for a state to the directory of the state.

The script name will be set to the SCRIPT_FILE constant.

Parameters
  • state – The state of which the script file should be saved

  • state_path_full (str) – The path to the file system storage location of the state

  • as_copy (bool) – Temporary storage flag to signal that the given path is not the new file_system_path

rafcon.core.storage.storage.save_semantic_data_for_state(state, state_path_full)

Saves the semantic data in a separate json file.

Parameters
  • state – The state of which the script file should be saved

  • state_path_full (str) – The path to the file system storage location of the state

rafcon.core.storage.storage.save_state_machine_to_path(state_machine, base_path, delete_old_state_machine=False, as_copy=False)

Saves a state machine recursively to the file system

The as_copy flag determines whether the state machine is saved as copy. If so (as_copy=True), some state machine attributes will be left untouched, such as the file_system_path or the dirty_flag.

Parameters
  • state_machine (rafcon.core.state_machine.StateMachine) – the state_machine to be saved

  • base_path (str) – base_path to which all further relative paths refers to

  • delete_old_state_machine (bool) – Whether to delete any state machine existing at the given path

  • as_copy (bool) – Whether to use a copy storage for the state machine

rafcon.core.storage.storage.save_state_recursively(state, base_path, parent_path, as_copy=False)

Recursively saves a state to a json file

It calls this method on all its substates.

Parameters
  • state – State to be stored

  • base_path – Path to the state machine

  • parent_path – Path to the parent state

  • as_copy (bool) – Temporary storage flag to signal that the given path is not the new file_system_path

Returns