def 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. :param state: The state of which the script file should be saved :param str state_path_full: The path to the file system storage location of the state :param bool as_copy: Temporary storage flag to signal that the given path is not the new file_system_path """ from rafcon.core.states.execution_state import ExecutionState if isinstance(state, ExecutionState): source_script_file = os.path.join(state.script.path, state.script.filename) destination_script_file = os.path.join(state_path_full, SCRIPT_FILE) try: write_file(destination_script_file, state.script_text) except Exception: logger.exception( "Storing of script file failed: {0} -> {1}".format( state.get_path(), destination_script_file)) raise if not source_script_file == destination_script_file and not as_copy: state.script.filename = SCRIPT_FILE state.script.path = state_path_full
def save_file_data(self, path): """ Implements the abstract method of the ExternalEditor class. """ try: # just create file with empty text first; this command also creates the whole path to the file filesystem.write_file(os.path.join(path, storage.SCRIPT_FILE), "", create_full_path=True) storage_utils.write_dict_to_json(self.model.state.semantic_data, os.path.join(path, storage.SEMANTIC_DATA_FILE)) except IOError as e: # Only happens if the file doesnt exist yet and would be written to the temp folder. # The method write_file doesn't create the path logger.error('The operating system raised an error: {}'.format(e))
def save_file_data(self, path): """ Implements the abstract method of the ExternalEditor class. """ sm = self.model.state.get_state_machine() if sm.marked_dirty and not self.saved_initial: try: # Save the file before opening it to update the applied changes. Use option create_full_path=True # to assure that temporary state_machines' script files are saved to # (their path doesnt exist when not saved) filesystem.write_file(os.path.join(path, storage.SCRIPT_FILE), self.view.get_text(), create_full_path=True) except IOError as e: # Only happens if the file doesnt exist yet and would be written to the temp folder. # The method write_file doesnt create the path logger.error('The operating system raised an error: {}'.format(e)) self.saved_initial = True