def execMp(self): settings = QSettings("NextGIS", "metatools") if not settings.value("tools/hasFGDC", False): return # check if metadata exists if not self.checkMetadata(): return # check matadata standard standard = MetaInfoStandard.tryDetermineStandard(self.metaProvider) if standard != MetaInfoStandard.FGDC: QMessageBox.critical(self.iface.mainWindow(), QCoreApplication.translate("Metatools", "Metatools"), QCoreApplication.translate("Metatools", "MP tool support only FGDC standard!") ) return # start tool mpFilePath = settings.value("tools/mp", "") errFilePath = settings.value("tools/err2html", "") tempPath = os.tempnam() temporaryMetafile = self.metaProvider.SaveToTempFile() result = '' try: import subprocess subprocess.check_call([mpFilePath, "-e", tempPath, temporaryMetafile], shell=throwShell, cwd=toolPath) if sys.hexversion >= 34013184: result = subprocess.check_output([errFilePath, tempPath], shell=throwShell, cwd=toolPath) else: # workaround for python < 2.7 # ... stderr=subprocess.STDOUT, stdin=subprocess.PIPE ... ! F****D Python 2.5 bug on windows! err2htmlProc = subprocess.Popen([errFilePath, tempPath], shell=throwShell, cwd=toolPath, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, stdin=subprocess.PIPE) err2htmlProc.stdin.close() result = err2htmlProc.communicate()[0] except: QMessageBox.critical(self.iface.mainWindow(), QCoreApplication.translate("Metatools", "Metatools"), QCoreApplication.translate("Metatools", "MP tool can't be runing: ") + unicode(sys.exc_info()[1]) ) return finally: if os.path.exists(tempPath): os.remove(tempPath) # explicit kill temporary metafile if os.path.exists(temporaryMetafile): os.remove(temporaryMetafile) # show result from metatoolsviewer import MetatoolsViewer dlg = MetatoolsViewer() dlg.setHtml(result) dlg.setWindowTitle(QCoreApplication.translate("Metatools", "MP result")) dlg.exec_()
def handleMessage(self, msg_type, desc, identifier, loc): #QMessageBox.information(None, "Error", desc + " Ident: " + identifier.toString() + " Line: " + QString(str(loc.line()))) from metatoolsviewer import MetatoolsViewer message_type = {0:'Debug', 1:'Warning', 2:'Critical', 3:'Fatal'} if msg_type > 1: self.errorOccured = True desc.replace('<p>', '') desc.replace('</p>', '') desc.replace("<body>", "<head><style>.XQuery-keyword, .XQuery-type {color: red;} infolabel {color: blue; text-weight: bold; text-size: 14px}</style></head><body>") #add styles desc.replace("<body>", "<infolabel>Problem type: </infolabel>%s <br/><infolabel>Problem line: </infolabel>%s <br/><infolabel>Problem description: </infolabel>" % (message_type[msg_type], loc.line())) #add info dlg = MetatoolsViewer() dlg.resize(dlg.width(), 200) dlg.setHtml(desc) dlg.setWindowTitle(self.windowTitle) dlg.exec_()