Esempio n. 1
0
def 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.

    :param base_path:
    :return: cleaned base_path
    :rtype: str
    """
    def warning_logger_message(insert_string):
        not_allowed_characters = "'" + "', '".join(REPLACED_CHARACTERS_FOR_NO_OS_LIMITATION.keys()) + "'"
        warnings.warn("{1} not allowed in {2} of {0}".format(base_path, not_allowed_characters, insert_string),
                      log.RAFCONDeprecationWarning)
    from rafcon.core.singleton import library_manager
    if library_manager.is_os_path_within_library_root_paths(base_path):
        library_path, library_name = library_manager.get_library_path_and_name_for_os_path(base_path)
        clean_library_path = clean_path(library_path)
        clean_library_name = clean_path(library_name)
        if library_name != clean_library_name or library_path != clean_library_path:
            warning_logger_message("library path")
        library_root_key = library_manager._get_library_root_key_for_os_path(base_path)
        library_root_path = library_manager._library_root_paths[library_root_key]
        clean_base_path = os.path.join(library_root_path, clean_library_path, clean_library_name)
    else:
        path_elements = base_path.split(os.path.sep)
        state_machine_folder_name = base_path.split(os.path.sep)[-1]
        path_elements[-1] = clean_path(state_machine_folder_name)
        if not state_machine_folder_name == path_elements[-1]:
            warning_logger_message("state machine folder name")
        clean_base_path = os.path.sep.join(path_elements)
    return clean_base_path
Esempio n. 2
0
    def _update_recently_opened_state_machines(self):
        """Update the sub menu Open Recent in File menu

        Method clean's first all menu items of the sub menu 'recent open', then insert the user menu item to clean
        recent opened state machine paths and finally insert menu items for all elements in recent opened state machines
        list.
        """
        if not self.registered_view:
            return

        for item in self.view.sub_menu_open_recently.get_children():
            self.view.sub_menu_open_recently.remove(item)

        menu_item = gui_helper_label.create_menu_item(
            "remove invalid paths", constants.ICON_ERASE,
            global_runtime_config.clean_recently_opened_state_machines)
        self.view.sub_menu_open_recently.append(menu_item)
        self.view.sub_menu_open_recently.append(Gtk.SeparatorMenuItem())

        for sm_path in global_runtime_config.get_config_value(
                "recently_opened_state_machines", []):
            # define label string
            root_state_name = gui_helper_state_machine.get_root_state_name_of_sm_file_system_path(
                sm_path)
            if root_state_name is None and not os.path.isdir(sm_path):
                root_state_name = 'NOT_ACCESSIBLE'
            label_string = "'{0}' in {1}".format(
                root_state_name,
                sm_path) if root_state_name is not None else sm_path

            # define icon of menu item
            is_in_libs = library_manager.is_os_path_within_library_root_paths(
                sm_path)
            button_image = constants.SIGN_LIB if is_in_libs else constants.BUTTON_OPEN

            # prepare state machine open call_back function
            sm_open_function = partial(self.on_open_activate, path=sm_path)

            # create and insert new menu item
            menu_item = gui_helper_label.create_menu_item(
                label_string, button_image, sm_open_function)
            self.view.sub_menu_open_recently.append(menu_item)

        self.view.sub_menu_open_recently.show_all()