コード例 #1
0
 def __init__(self, currentWorkspace, currentProject, importType, messages):
     self.currentWorkspace = currentWorkspace
     self.currentProject = currentProject
     self._view = ConfirmImportMessagesView(self)
     self.log = logging.getLogger(__name__)
     self.messages = messages
     self.importedMessages = messages
     self.excludedMessages = []
     self.importType = importType
     self.finish_cb = None
コード例 #2
0
 def __init__(self, currentWorkspace, currentProject, importType, messages):
     self.currentWorkspace = currentWorkspace
     self.currentProject = currentProject
     self._view = ConfirmImportMessagesView(self)
     self.log = logging.getLogger(__name__)
     self.messages = messages
     self.importedMessages = messages
     self.excludedMessages = []
     self.importType = importType
     self.finish_cb = None
コード例 #3
0
class ConfirmImportMessagesController(object):
    '''Controller to request the user to confirm the import process of
    provided messages'''
    def __init__(self, currentWorkspace, currentProject, importType, messages):
        self.currentWorkspace = currentWorkspace
        self.currentProject = currentProject
        self._view = ConfirmImportMessagesView(self)
        self.log = logging.getLogger(__name__)
        self.messages = messages
        self.importedMessages = messages
        self.excludedMessages = []
        self.importType = importType
        self.finish_cb = None

    @property
    def view(self):
        return self._view

    def cancelButton_clicked_cb(self, widget):
        """Callback executed when the user wants to cancel the import"""
        self.stopFlag = True
        self._view.destroy()

    def importButton_clicked_cb(self, widget):
        """Callback executed when the user wants to import messages"""
        if self.currentProject is None:
            self.log.error("No project is open")
            return

        # retrieve symbol name
        symbolName = self._view.nameOfCreatedSymbolEntry.get_text()
        if symbolName is None or len(symbolName) < 1:
            self.displayErrorMessage(_("Specify the name of new symbol"))
            return

        found = False
        for symbol in self.currentProject.getVocabulary().getSymbols():
            if symbol.getName() == symbolName:
                found = True
                break

        if found:
            self.displayErrorMessage(
                _("The provided symbol name already exists."))
            return

        # Should we consider meta datas of excluded messages
        if self._view.removeDuplicatedMessagesCheckButton.get_active(
        ) and self._view.keepPropertiesOfDuplicatedMessagesCheckButton.get_active(
        ):
            # Retrieve the 'excluded' messages and retrieve their properties
            for message in self.excludedMessages:
                # search for an included message to register properties
                eq_message = None
                for importedMessage in self.importedMessages:
                    if importedMessage.getStringData(
                    ) == message.getStringData():
                        eq_message = importedMessage
                        break
                if eq_message is not None:
                    for property in message.getProperties():
                        eq_message.addExtraProperty(property)

        # We create a session with each message
        session = Session(str(uuid.uuid4()), "Session 1", "")
        for message in self.importedMessages:
            session.addMessage(message)
        # We register the session in the vocabulary of the project
        self.currentProject.getVocabulary().addSession(session)

        # We register each message in the vocabulary of the project
        for message in self.importedMessages:
            self.currentProject.getVocabulary().addMessage(message)
            message.setSession(session)

        # We create a default symbol dedicated for this
        symbol = Symbol(str(uuid.uuid4()), symbolName, self.currentProject)
        for message in self.importedMessages:
            symbol.addMessage(message)
        # We register the symbol in the vocabulary of the project
        self.currentProject.getVocabulary().addSymbol(symbol)

        # Add the environmental dependencies to the project
        #        if fetchEnv:
        #            project.getConfiguration().setVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_ENVIRONMENTAL_DEPENDENCIES,
        #                                                                       self.envDeps.getEnvData())
        # Computes current date
        date = datetime.now()
        description = "No description (yet not implemented)"

        # We also save the session and the messages in the workspace
        trace = ImportedTrace(str(uuid.uuid4()), date, self.importType,
                              description, self.currentProject.getName())
        trace.addSession(session)
        for message in self.importedMessages:
            trace.addMessage(message)

        self.currentWorkspace.addImportedTrace(trace)

        # Now we save the workspace
        self.currentWorkspace.saveConfigFile()

        self._view.destroy()

        if self.finish_cb is not None:
            GObject.idle_add(self.finish_cb)

    def displayErrorMessage(self, errorMessage):
        """Display to the user the provided errorMessage"""
        if errorMessage is not None:
            self._view.errorImage.show()
            self._view.errorLabel.set_label(errorMessage)
            self._view.errorLabel.show()
        else:
            self._view.errorImage.hide()
            self.showNumberOfImportedMessages()

    def showNumberOfImportedMessages(self):
        """Set the text which shows to the user the number
        of messages that will be imported."""
        self._view.errorLabel.set_label(
            _("{0} messages will be imported").format(
                len(self.importedMessages)))
        self._view.errorLabel.show()

    def removeDuplicatedMessagesCheckButton_toggled_cb(self, widget):
        """Callback executed when the user toggle (or untoggle) the
        checkbox to deactivate the duplication of payloads in import"""
        if self._view.removeDuplicatedMessagesCheckButton.get_active():
            self._view.keepPropertiesOfDuplicatedMessagesCheckButton.set_sensitive(
                True)
            self.removeDuplicatedMessagesFromImport()
        else:
            self._view.keepPropertiesOfDuplicatedMessagesCheckButton.set_sensitive(
                False)
            self.importedMessages = self.messages

        self.showNumberOfImportedMessages()

    def removeDuplicatedMessagesFromImport(self):
        """Remove duplicated messages"""
        self.importedMessages = []
        self.excludedMessages = []

        existingMessages = []
        for symbol in self.currentProject.getVocabulary().getSymbols():
            existingMessages.extend(symbol.getMessages())

        # Remove duplicated messages
        for message in self.messages:
            found = False

            # we verify its a not an empty message
            if len(message.getStringData()) > 0:
                for m in self.importedMessages:
                    if m.getStringData() == message.getStringData():
                        found = True
                        break
                if not found:
                    for m in existingMessages:
                        if m.getStringData() == message.getStringData():
                            found = True
                            break
                    if not found:
                        self.importedMessages.append(message)
                    else:
                        self.excludedMessages.append(message)
                else:
                    self.excludedMessages.append(message)

    def run(self):
        """Run method"""
        self._view.errorImage.hide()
        self._view.errorLabel.show()
        self._view.errorLabel.set_label(
            _("{0} messages will be imported").format(
                len(self.importedMessages)))
        self._view.nameOfCreatedSymbolEntry.set_text("IMPORTS")
        self._view.removeDuplicatedMessagesCheckButton.set_active(True)
        self._view.keepPropertiesOfDuplicatedMessagesCheckButton.show()
        self._view.keepPropertiesOfDuplicatedMessagesCheckButton.set_active(
            True)

        self._view.run()

    def setFinish_cb(self, function):
        """Set the callback to execute when import is finished"""
        self.finish_cb = function
コード例 #4
0
class ConfirmImportMessagesController(object):
    '''Controller to request the user to confirm the import process of
    provided messages'''

    def __init__(self, currentWorkspace, currentProject, importType, messages):
        self.currentWorkspace = currentWorkspace
        self.currentProject = currentProject
        self._view = ConfirmImportMessagesView(self)
        self.log = logging.getLogger(__name__)
        self.messages = messages
        self.importedMessages = messages
        self.excludedMessages = []
        self.importType = importType
        self.finish_cb = None

    @property
    def view(self):
        return self._view

    def cancelButton_clicked_cb(self, widget):
        """Callback executed when the user wants to cancel the import"""
        self.stopFlag = True
        self._view.destroy()

    def importButton_clicked_cb(self, widget):
        """Callback executed when the user wants to import messages"""
        if self.currentProject is None:
            self.log.error("No project is open")
            return

        # retrieve symbol name
        symbolName = self._view.nameOfCreatedSymbolEntry.get_text()
        if symbolName is None or len(symbolName) < 1:
            self.displayErrorMessage(_("Specify the name of new symbol"))
            return

        found = False
        for symbol in self.currentProject.getVocabulary().getSymbols():
            if symbol.getName() == symbolName:
                found = True
                break

        if found:
            self.displayErrorMessage(_("The provided symbol name already exists."))
            return

        # Should we consider meta datas of excluded messages
        if self._view.removeDuplicatedMessagesCheckButton.get_active() and self._view.keepPropertiesOfDuplicatedMessagesCheckButton.get_active():
            # Retrieve the 'excluded' messages and retrieve their properties
            for message in self.excludedMessages:
                # search for an included message to register properties
                eq_message = None
                for importedMessage in self.importedMessages:
                    if importedMessage.getStringData() == message.getStringData():
                        eq_message = importedMessage
                        break
                if eq_message is not None:
                    for property in message.getProperties():
                        eq_message.addExtraProperty(property)

        # We create a session with each message
        session = Session(str(uuid.uuid4()), "Session 1", "")
        for message in self.importedMessages:
            session.addMessage(message)
        # We register the session in the vocabulary of the project
        self.currentProject.getVocabulary().addSession(session)

        # We register each message in the vocabulary of the project
        for message in self.importedMessages:
            self.currentProject.getVocabulary().addMessage(message)
            message.setSession(session)

        # We create a default symbol dedicated for this
        symbol = Symbol(str(uuid.uuid4()), symbolName, self.currentProject)
        for message in self.importedMessages:
            symbol.addMessage(message)
        # We register the symbol in the vocabulary of the project
        self.currentProject.getVocabulary().addSymbol(symbol)

        # Add the environmental dependencies to the project
#        if fetchEnv:
#            project.getConfiguration().setVocabularyInferenceParameter(ProjectConfiguration.VOCABULARY_ENVIRONMENTAL_DEPENDENCIES,
#                                                                       self.envDeps.getEnvData())
        # Computes current date
        date = datetime.now()
        description = "No description (yet not implemented)"

        # We also save the session and the messages in the workspace
        trace = ImportedTrace(str(uuid.uuid4()), date, self.importType, description, self.currentProject.getName())
        trace.addSession(session)
        for message in self.importedMessages:
            trace.addMessage(message)

        self.currentWorkspace.addImportedTrace(trace)

        # Now we save the workspace
        self.currentWorkspace.saveConfigFile()

        self._view.destroy()

        if self.finish_cb is not None:
            GObject.idle_add(self.finish_cb)

    def displayErrorMessage(self, errorMessage):
        """Display to the user the provided errorMessage"""
        if errorMessage is not None:
            self._view.errorImage.show()
            self._view.errorLabel.set_label(errorMessage)
            self._view.errorLabel.show()
        else:
            self._view.errorImage.hide()
            self.showNumberOfImportedMessages()

    def showNumberOfImportedMessages(self):
        """Set the text which shows to the user the number
        of messages that will be imported."""
        self._view.errorLabel.set_label(_("{0} messages will be imported").format(len(self.importedMessages)))
        self._view.errorLabel.show()

    def removeDuplicatedMessagesCheckButton_toggled_cb(self, widget):
        """Callback executed when the user toggle (or untoggle) the
        checkbox to deactivate the duplication of payloads in import"""
        if self._view.removeDuplicatedMessagesCheckButton.get_active():
            self._view.keepPropertiesOfDuplicatedMessagesCheckButton.set_sensitive(True)
            self.removeDuplicatedMessagesFromImport()
        else:
            self._view.keepPropertiesOfDuplicatedMessagesCheckButton.set_sensitive(False)
            self.importedMessages = self.messages

        self.showNumberOfImportedMessages()

    def removeDuplicatedMessagesFromImport(self):
        """Remove duplicated messages"""
        self.importedMessages = []
        self.excludedMessages = []

        existingMessages = []
        for symbol in self.currentProject.getVocabulary().getSymbols():
            existingMessages.extend(symbol.getMessages())

        # Remove duplicated messages
        for message in self.messages:
            found = False

            # we verify its a not an empty message
            if len(message.getStringData()) > 0:
                for m in self.importedMessages:
                    if m.getStringData() == message.getStringData():
                        found = True
                        break
                if not found:
                    for m in existingMessages:
                        if m.getStringData() == message.getStringData():
                            found = True
                            break
                    if not found:
                        self.importedMessages.append(message)
                    else:
                        self.excludedMessages.append(message)
                else:
                    self.excludedMessages.append(message)

    def run(self):
        """Run method"""
        self._view.errorImage.hide()
        self._view.errorLabel.show()
        self._view.errorLabel.set_label(_("{0} messages will be imported").format(len(self.importedMessages)))
        self._view.nameOfCreatedSymbolEntry.set_text("IMPORTS")
        self._view.removeDuplicatedMessagesCheckButton.set_active(True)
        self._view.keepPropertiesOfDuplicatedMessagesCheckButton.show()
        self._view.keepPropertiesOfDuplicatedMessagesCheckButton.set_active(True)

        self._view.run()

    def setFinish_cb(self, function):
        """Set the callback to execute when import is finished"""
        self.finish_cb = function