def loadVocabulary(xmlRoot, namespace_project, namespace_common, version, project): vocabulary = Vocabulary() if version == "0.1": # Messages for xmlMessage in xmlRoot.findall("{" + namespace_project + "}messages/{" + namespace_common + "}message"): message = AbstractMessageFactory.loadFromXML( xmlMessage, namespace_common, version) if message is not None: vocabulary.addMessage(message) # Symbols for xmlSymbol in xmlRoot.findall("{" + namespace_project + "}symbols/{" + namespace_project + "}symbol"): symbol = Symbol.loadSymbol(xmlSymbol, namespace_project, namespace_common, version, project, vocabulary) if symbol is not None: vocabulary.addSymbol(symbol) # Sessions for xmlSession in xmlRoot.findall("{" + namespace_project + "}sessions/{" + namespace_common + "}session"): session = Session.loadFromXML(xmlSession, namespace_project, namespace_common, version, vocabulary) if session is not None: vocabulary.addSession(session) return vocabulary
def traceSessionNewAction_activate_cb(self, button): session = Session(str(uuid.uuid4()), _("Empty Session"), "") self.currentTrace.addSession(session) self.workspace.saveConfigFile(overrideTraces=[self.currentTrace.id]) self.log.info("New empty session was created: {0} (id={1})".format( session.name, session.id)) self._refreshTraceList([self.currentTrace.id])
def loadTrace(xmlRoot, namespace_workspace, namespace_common, version, pathOfTraces): if version == "0.1": date = TypeConvertor.xsdDatetime2PythonDatetime( str(xmlRoot.get("date"))) type = xmlRoot.get("type") description = xmlRoot.get("description", "") id = str(xmlRoot.get("id")) name = xmlRoot.get("name") importedTrace = ImportedTrace(id, date, type, description, name) tracesFile = os.path.join(pathOfTraces, "{0}.gz".format(id)) if not os.path.isfile(tracesFile): logging.warn( "The trace file {0} is referenced but doesn't exist.". format(tracesFile)) else: gzipFile = gzip.open(tracesFile, 'rb') xml_content = gzipFile.read() gzipFile.close() tree = etree.parse(StringIO(xml_content)) xmlRoot = tree.getroot() # We retrieve the pool of messages xmlMessages = xmlRoot.find("{" + namespace_workspace + "}messages") if xmlMessages is not None: for xmlMessage in xmlMessages.findall("{" + namespace_common + "}message"): message = AbstractMessageFactory.loadFromXML( xmlMessage, namespace_common, version) if message is not None: importedTrace.addMessage(message) # We retrieve the sessions if xmlRoot.find("{" + namespace_workspace + "}sessions") is not None: xmlSessions = xmlRoot.find("{" + namespace_workspace + "}sessions") for xmlSession in xmlSessions.findall("{" + namespace_common + "}session"): session = Session.loadFromXML(xmlSession, namespace_workspace, namespace_common, version, importedTrace) if session is not None: importedTrace.addSession(session) return importedTrace return None
def loadVocabulary(xmlRoot, namespace_project, namespace_common, version, project): vocabulary = Vocabulary() if version == "0.1": # Messages for xmlMessage in xmlRoot.findall("{" + namespace_project + "}messages/{" + namespace_common + "}message"): message = AbstractMessageFactory.loadFromXML(xmlMessage, namespace_common, version) if message is not None: vocabulary.addMessage(message) # Symbols for xmlSymbol in xmlRoot.findall("{" + namespace_project + "}symbols/{" + namespace_project + "}symbol"): symbol = Symbol.loadSymbol(xmlSymbol, namespace_project, namespace_common, version, project, vocabulary) if symbol is not None: vocabulary.addSymbol(symbol) # Sessions for xmlSession in xmlRoot.findall("{" + namespace_project + "}sessions/{" + namespace_common + "}session"): session = Session.loadFromXML(xmlSession, namespace_project, namespace_common, version, vocabulary) if session is not None: vocabulary.addSession(session) return vocabulary
def loadTrace(xmlRoot, namespace_workspace, namespace_common, version, pathOfTraces): if version == "0.1": date = TypeConvertor.xsdDatetime2PythonDatetime(str(xmlRoot.get("date"))) type = xmlRoot.get("type") description = xmlRoot.get("description", "") id = xmlRoot.get("id") name = xmlRoot.get("name") importedTrace = ImportedTrace(id, date, type, description, name) tracesFile = os.path.join(pathOfTraces, str(id) + ".gz") if not os.path.isfile(tracesFile): logging.warn("The trace file " + str(tracesFile) + " is referenced but doesn't exist.") else: gzipFile = gzip.open(tracesFile, 'rb') xml_content = gzipFile.read() gzipFile.close() tree = etree.parse(StringIO(xml_content)) xmlRoot = tree.getroot() # We retrieve the pool of messages if xmlRoot.find("{" + namespace_workspace + "}messages") != None: xmlMessages = xmlRoot.find("{" + namespace_workspace + "}messages") for xmlMessage in xmlMessages.findall("{" + namespace_common + "}message"): message = AbstractMessageFactory.loadFromXML(xmlMessage, namespace_common, version) if message != None: importedTrace.addMessage(message) # We retrieve the sessions if xmlRoot.find("{" + namespace_workspace + "}sessions") != None: xmlSessions = xmlRoot.find("{" + namespace_workspace + "}sessions") for xmlSession in xmlSessions.findall("{" + namespace_common + "}session"): session = Session.loadFromXML(xmlSession, namespace_workspace, namespace_common, version, importedTrace) if session != None: importedTrace.addSession(session) return importedTrace return None
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 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)