Пример #1
0
class ProjectLoader(object):
    def __init__(self, project_file_ext):
        self.project_reader = ProjectReader(project_file_ext)
        self.workspace_loader = WorkspaceLoader()
        self.plot_loader = PlotsLoader()
        self.decoder_factory = DecoderFactory()
        self.project_file_ext = project_file_ext

    def load_project(self, file_name, load_workspaces=True):
        """
        Will load the project in the given file_name
        :param file_name: String or string castable object; the file_name of the project
        :param load_workspaces: Bool; True if you want ProjectLoader to handle loading workspaces else False.
        :return: Bool; True if all workspace loaded successfully, False if not loaded successfully.
        """
        # It can be expected that if at this point it is NoneType that it's an error
        if file_name is None:
            return

        # Read project
        self.project_reader.read_project(file_name)

        directory = os.path.dirname(file_name)
        # Load in the workspaces
        if load_workspaces:
            self.workspace_loader.load_workspaces(
                directory=directory,
                workspaces_to_load=self.project_reader.workspace_names)

        workspace_success = _confirm_all_workspaces_loaded(
            workspaces_to_confirm=self.project_reader.workspace_names)

        if workspace_success:
            # Load plots
            if self.project_reader.plot_list is not None:
                self.plot_loader.load_plots(self.project_reader.plot_list)

            # Load interfaces
            if self.project_reader.interface_list is not None:
                self.load_interfaces(directory=directory)

        return workspace_success

    def load_interfaces(self, directory):
        for interface in self.project_reader.interface_list:
            # Find decoder
            decoder = self.decoder_factory.find_decoder(interface["tag"])

            # Decode and Show the interface
            try:
                decoded_interface = decoder.decode(interface, directory)
                decoded_interface.show()
            except Exception as e:
                # Catch any exception and log it for the encoder
                if isinstance(e, KeyboardInterrupt):
                    raise
                logger.warning(
                    "Project Loader: An interface could not be loaded error: "
                    + str(e))
Пример #2
0
class ProjectLoader(object):
    def __init__(self, project_file_ext):
        self.project_reader = ProjectReader(project_file_ext)
        self.workspace_loader = WorkspaceLoader()
        self.plot_loader = PlotsLoader()
        self.decoder_factory = DecoderFactory()
        self.project_file_ext = project_file_ext

    def load_project(self, file_name, load_workspaces=True):
        """
        Will load the project in the given file_name
        :param file_name: String or string castable object; the file_name of the project
        :param load_workspaces: Bool; True if you want ProjectLoader to handle loading workspaces else False.
        :return: Bool; True if all workspace loaded successfully, False if not loaded successfully.
        """
        # It can be expected that if at this point it is NoneType that it's an error
        if file_name is None:
            return

        # Read project
        self.project_reader.read_project(file_name)

        directory = os.path.dirname(file_name)
        # Load in the workspaces
        if load_workspaces:
            self.workspace_loader.load_workspaces(directory=directory,
                                                  workspaces_to_load=self.project_reader.workspace_names)

        workspace_success = _confirm_all_workspaces_loaded(workspaces_to_confirm=self.project_reader.workspace_names)

        if workspace_success:
            # Load plots
            if self.project_reader.plot_list is not None:
                self.plot_loader.load_plots(self.project_reader.plot_list)

            # Load interfaces
            if self.project_reader.interface_list is not None:
                self.load_interfaces(directory=directory)

        return workspace_success

    def load_interfaces(self, directory):
        for interface in self.project_reader.interface_list:
            # Find decoder
            decoder = self.decoder_factory.find_decoder(interface["tag"])

            # Decode and Show the interface
            try:
                decoded_interface = decoder.decode(interface, directory)
                decoded_interface.show()
            except Exception as e:
                # Catch any exception and log it for the encoder
                if isinstance(e, KeyboardInterrupt):
                    raise
                logger.warning("Project Loader: An interface could not be loaded error: " + str(e))
 def test_decoder_is_in_decoder_factory(self):
     # Shows that the decoder has been registered on import of something from mantidqt.widget.instrumentview
     found_decoder = DecoderFactory.find_decoder("InstrumentView")
     self.assertIs(InstrumentViewDecoder, found_decoder.__class__)
Пример #4
0
 def test_find_decoder_can_find_an_decoder(self):
     self.assertNotEqual(None, DecoderFactory.find_decoder("InstrumentView"))
Пример #5
0
 def test_find_decoder_can_find_an_decoder(self):
     self.assertNotEqual(None,
                         DecoderFactory.find_decoder("InstrumentView"))
Пример #6
0
 def test_decoder_is_in_decoder_factory(self):
     # Shows that the decoder has been registered on import of something from mantidqt.widget.instrumentview
     found_decoder = DecoderFactory.find_decoder("InstrumentView")
     self.assertIs(InstrumentViewDecoder, found_decoder.__class__)