def newEmptyImportedTrace(self, name, description=""): """This function is in charge of creating an empty `ImportedTrace`. :param name: 'name' of the new trace. :param description (optional): description of the new trace.""" newTrace = ImportedTrace(str(uuid.uuid4()), datetime.datetime.now(), "UNKNOWN", description, name) self.addImportedTrace(newTrace) return newTrace
def mergeImportedTraces(self, traceIds, name, keep=True): """This methods allows to merge multiple traces. The merged traces gets a new unique id. If the 'keep' parameter is True, a copy of the initial traces is kept. We retrieve the 'ImportedTrace' object from its ID. Then we merge all traces' messages and sessions into a new 'ImportedTrace'.""" messages = {} sessions = {} names = [] types = [] for traceId in traceIds: trace = self.getImportedTrace(traceId) messages.update(trace.messages) sessions.update(trace.sessions) names.append("'{0}'".format(trace.name)) # If the type is already a multiple type merge, types are # comma separated values. types.extend(trace.type.split(";")) if keep is False: self.removeImportedTrace(trace) # The type of the new trace is a list of the multiple types of # the traces to be merged. newTraceType = "{0}".format(";".join(set(types))) description = "Merge of traces {0} and {1}".format( ', '.join(names[:-1]), names[-1]) newTrace = ImportedTrace(str(uuid.uuid4()), datetime.datetime.now(), newTraceType, description, name) newTrace.messages = messages newTrace.sessions = sessions self.addImportedTrace(newTrace) return newTrace
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)