Пример #1
0
    def menu_item_remove_libraries_or_root_clicked(self, menu_item):
        """Removes library from hard drive after request second confirmation"""

        menu_item_text = self.get_menu_item_text(menu_item)

        logger.info("Delete item '{0}' pressed.".format(menu_item_text))
        model, path = self.view.get_selection().get_selected()
        if path:
            # Second confirmation to delete library
            tree_m_row = self.filter[path]
            library_os_path, library_path, library_name, item_key = self.extract_library_properties_from_selected_row()
            library_file_system_path = library_os_path

            if "root" in menu_item_text:
                button_texts = [menu_item_text + "from tree and config", "Cancel"]
                partial_message = "This will remove the library root from your configuration (config.yaml)."
            else:
                button_texts = [menu_item_text, "Cancel"]
                partial_message = "This folder will be removed from your hard drive! Do you really want to do that?"

            message_string = "You have chosen to {2} with " \
                             "\n\nlibrary tree path:   {0}" \
                             "\n\nphysical path:        {1}\n\n\n" \
                             "{3}" \
                             "".format(os.path.join(self.convert_if_human_readable(tree_m_row[self.LIB_PATH_STORAGE_ID]),
                                                    item_key),
                                       library_file_system_path,
                                       menu_item_text.lower(),
                                       partial_message)

            width = 8*len("physical path:        " + library_file_system_path)
            dialog = RAFCONButtonDialog(message_string, button_texts, message_type=Gtk.MessageType.QUESTION,
                                        parent=self.get_root_window(), width=min(width, 1400))
            response_id = dialog.run()
            dialog.destroy()
            if response_id == 1:
                if "root" in menu_item_text:
                    logger.info("Remove library root key '{0}' from config.".format(item_key))
                    from rafcon.gui.singleton import global_config
                    library_paths = global_config.get_config_value('LIBRARY_PATHS')
                    del library_paths[tree_m_row[self.LIB_KEY_STORAGE_ID]]
                    global_config.save_configuration()
                    self.model.library_manager.refresh_libraries()
                elif "libraries" in menu_item_text:
                    logger.debug("Remove of all libraries in {} is triggered.".format(library_os_path))
                    import shutil
                    shutil.rmtree(library_os_path)
                    self.model.library_manager.refresh_libraries()
                else:

                    logger.debug("Remove of Library {} is triggered.".format(library_os_path))
                    self.model.library_manager.remove_library_from_file_system(library_path,
                                                                               library_name)
            elif response_id in [2, -4]:
                pass
            else:
                logger.warning("Response id: {} is not considered".format(response_id))

            return True
        return False
Пример #2
0
    def menu_item_add_library_root_clicked(self, widget):

        logger.info("Get new path and mounting key.")
        from rafcon.gui import interface
        from rafcon.gui.singleton import global_config, global_runtime_config

        _path = interface.save_folder("Please choose the folder to be mounted and insert your mounting key.",
                                      "insert your mounting key here")

        if _path is None:
            return
        path_elements = _path.split(os.path.sep)
        library_root_key = path_elements[-1]  # the file/folder name is the mounting key
        library_root_path = os.path.sep.join(path_elements[:-1])

        logger.info("Add new library root '{0}: {1}' to config.".format(library_root_key, library_root_path))
        library_paths = global_config.get_config_value('LIBRARY_PATHS')
        library_paths[library_root_key] = library_root_path
        global_config.save_configuration()
        self.model.library_manager.refresh_libraries()
Пример #3
0
def test_rename_library_root(caplog):
    testing_utils.initialize_environment(gui_already_started=False,
                                         libraries={})

    try:
        from rafcon.gui.helpers.state_machine import rename_library_root
        from rafcon.gui.singleton import global_config

        state_machine_path = os.path.abspath(
            os.path.join(testing_utils.TEST_STATE_MACHINES_PATH,
                         STATE_MACHINE_NAME))

        rename_library_root(CURRENT_LIBRARY_ROOT_NAME, NEW_LIBRARY_ROOT_NAME)
        library_manager.clean_loaded_libraries()
        library_manager.refresh_libraries()

        testing_utils.shutdown_environment(caplog=caplog,
                                           unpatch_threading=False)
        testing_utils.initialize_environment(
            gui_already_started=False,
            libraries={"new_generic": testing_utils.GENERIC_PATH})
        library = storage.load_state_machine_from_path(state_machine_path)

        assert library is not None

        library_paths = global_config.get_config_value('LIBRARY_PATHS')
        del library_paths[CURRENT_LIBRARY_ROOT_NAME]
        global_config.save_configuration()

        rename_library_root(NEW_LIBRARY_ROOT_NAME, CURRENT_LIBRARY_ROOT_NAME)
        library_manager.clean_loaded_libraries()
        library_manager.refresh_libraries()

        library = storage.load_state_machine_from_path(state_machine_path)

        assert library is not None
    finally:
        testing_utils.shutdown_environment(caplog=caplog,
                                           unpatch_threading=False)
Пример #4
0
    def delete_button_clicked(self, widget):
        """Removes library from hard drive after request second confirmation"""
        logger.info("delete library" + str(widget) + str(widget.get_label()))
        model, path = self.view.get_selection().get_selected()
        if path:
            # Second confirmation to delete library
            tree_m_row = self.tree_store[path]
            # assert isinstance(tree_m_row[self.ITEM_STORAGE_ID], str)
            library_file_system_path = tree_m_row[self.OS_PATH_STORAGE_ID]

            if "root" in widget.get_label():
                button_texts = [
                    widget.get_label() + "from tree and config", "Cancel"
                ]
                partial_message = "This will remove the library root from your configuration (config.yaml)."
            else:
                button_texts = [widget.get_label(), "Cancel"]
                partial_message = "This folder will be removed from hard drive! You really wanna do that?"

            message_string = "You choose to {2} with " \
                             "\n\nlibrary tree path:   {0}" \
                             "\n\nphysical path:        {1}.\n\n\n"\
                             "{3}" \
                             "".format(os.path.join(self.convert_if_human_readable(tree_m_row[self.LIB_PATH_STORAGE_ID]),
                                                    tree_m_row[self.ID_STORAGE_ID]),
                                       library_file_system_path,
                                       widget.get_label().lower(),
                                       partial_message)

            width = 8 * len("physical path:        " +
                            library_file_system_path)
            dialog = RAFCONButtonDialog(message_string,
                                        button_texts,
                                        message_type=gtk.MESSAGE_QUESTION,
                                        parent=self.get_root_window(),
                                        width=min(width, 1400))
            response_id = dialog.run()
            dialog.destroy()
            if response_id == 1:
                if "root" in widget.get_label():
                    logger.info(
                        "Remove library root key '{0}' from config.".format(
                            tree_m_row[self.ID_STORAGE_ID]))
                    from rafcon.gui.singleton import global_config
                    library_paths = global_config.get_config_value(
                        'LIBRARY_PATHS')
                    del library_paths[tree_m_row[self.LIB_KEY_STORAGE_ID]]
                    global_config.save_configuration()
                    self.model.library_manager.refresh_libraries()
                elif "libraries" in widget.get_label():
                    logger.debug(
                        "Remove of all libraries in {} is triggered.".format(
                            tree_m_row[self.OS_PATH_STORAGE_ID]))
                    import shutil
                    shutil.rmtree(tree_m_row[self.OS_PATH_STORAGE_ID])
                    self.model.library_manager.refresh_libraries()
                else:
                    logger.debug("Remove of Library {} is triggered.".format(
                        tree_m_row[self.ITEM_STORAGE_ID]))
                    self.model.library_manager.remove_library_from_file_system(
                        tree_m_row[self.LIB_PATH_STORAGE_ID],
                        tree_m_row[self.ID_STORAGE_ID])
            elif response_id in [2, -4]:
                pass
            else:
                logger.warning(
                    "Response id: {} is not considered".format(response_id))

            return True
        return False