[processing] better error handling and some minor fixes

solved issue with trailing characters when calling mkdir
solved issue with non-ascii characters in help files
This commit is contained in:
Victor Olaya 2013-09-23 13:31:47 +02:00
parent c55c2ab82f
commit e4c60adcd3
5 changed files with 33 additions and 24 deletions

View File

@ -16,6 +16,7 @@
* *
***************************************************************************
"""
import sys
__author__ = 'Victor Olaya'
__date__ = 'August 2012'
@ -71,11 +72,16 @@ class Processing:
'''Adding a new provider automatically initializes it, so there is no need to do it in advance'''
#Note: this might slow down the initialization process if there are many new providers added.
#Should think of a different solution
provider.initializeSettings()
Processing.providers.append(provider)
ProcessingConfig.loadSettings()
if updateList:
Processing.updateAlgsList()
try:
provider.initializeSettings()
Processing.providers.append(provider)
ProcessingConfig.loadSettings()
if updateList:
Processing.updateAlgsList()
except:
ProcessingLog.addToLog(ProcessingLog.LOG_ERROR, "Could not load provider:"
+ provider.getDescription() + "\n" + sys.exc_info()[0])
Processing.removeProvider(provider)
@staticmethod
def removeProvider(provider):

View File

@ -96,7 +96,7 @@ class AlgorithmExecutionDialog(QtGui.QDialog):
html = None
try:
if self.alg.helpFile():
helpFile = self.alg.helpFile()
helpFile = self.alg.helpFile()
else:
html = "<h2>Sorry, no help is available for this algorithm.</h2>"
except WrongHelpFileException, e:
@ -249,8 +249,7 @@ class AlgorithmExecutionDialog(QtGui.QDialog):
return
except:
QMessageBox.critical(self, "Unable to execute algorithm", "Wrong or missing parameter values")
@pyqtSlot()
def finish(self):
keepOpen = ProcessingConfig.getSetting(ProcessingConfig.KEEP_DIALOG_OPEN)
if self.iterateParam is None:
@ -265,7 +264,7 @@ class AlgorithmExecutionDialog(QtGui.QDialog):
if self.alg.getHTMLOutputsCount() > 0:
self.setInfo("HTML output has been generated by this algorithm.\nOpen the results dialog to check it.")
@pyqtSlot(str)
def error(self, msg):
QApplication.restoreOverrideCursor()
keepOpen = ProcessingConfig.getSetting(ProcessingConfig.KEEP_DIALOG_OPEN)
@ -274,15 +273,14 @@ class AlgorithmExecutionDialog(QtGui.QDialog):
QMessageBox.critical(self, "Error", msg)
self.close()
else:
self.resetGUI()
#self.setInfo(msg, True)
self.resetGUI()
self.tabWidget.setCurrentIndex(1) # log tab
@pyqtSlot(int)
def iterate(self, i):
self.setInfo("<b>Algorithm %s iteration #%i completed</b>" % (self.alg.name, i))
@pyqtSlot()
def cancel(self):
self.setInfo("<b>Algorithm %s canceled</b>" % self.alg.name)
try:
@ -295,31 +293,30 @@ class AlgorithmExecutionDialog(QtGui.QDialog):
def resetGUI(self):
QApplication.restoreOverrideCursor()
self.progressLabel.setText("")
self.progress.setMaximum(100)
self.progress.setValue(0)
self.runButton.setEnabled(True)
self.buttonBox.button(QtGui.QDialogButtonBox.Close).setEnabled(True)
self.buttonBox.button(QtGui.QDialogButtonBox.Cancel).setEnabled(False)
@pyqtSlot(str)
@pyqtSlot(str, bool)
def setInfo(self, msg, error = False):
if error:
self.logText.append('<span style="color:red">' + msg + '</span>')
else:
self.logText.append(msg)
@pyqtSlot(str)
def setCommand(self, cmd):
if self.showDebug:
self.setInfo('<tt>' + cmd + '<tt>')
@pyqtSlot(str)
def setDebugInfo(self, msg):
if self.showDebug:
self.setInfo('<span style="color:blue">' + msg + '</span>')
@pyqtSlot(str)
def setConsoleInfo(self, msg):
if self.showDebug:
self.setCommand('<span style="color:darkgray">' + msg + '</span>')

View File

@ -26,6 +26,7 @@ __revision__ = '$Format:%H$'
import pickle
from processing.tools.system import *
import os
import codecs
class Help2Html():
@ -39,7 +40,7 @@ class Help2Html():
self.alg = alg
f = open(helpFile, "rb")
self.descriptions = pickle.load(f)
s = "<h2>Algorithm description</h2>\n"
s = "<html><body><h2>Algorithm description</h2>\n"
s += "<p>" + self.getDescription(self.ALG_DESC) + "</p>\n"
s += "<h2>Input parameters</h2>\n"
for param in self.alg.parameters:
@ -49,9 +50,11 @@ class Help2Html():
for out in self.alg.outputs:
s += "<h3>" + out.description + "</h3>\n"
s += "<p>" + self.getDescription(out.name) + "</p>\n"
s += "</body></html>"
filename = tempFolder() + os.sep + "temphelp.html"
tempHtml = open(filename, "w")
tempHtml = codecs.open(filename, "w", encoding = 'utf-8')
tempHtml.write(s)
tempHtml.close()
return filename

View File

@ -46,12 +46,14 @@ class UnthreadedAlgorithmExecutor:
return True
except GeoAlgorithmExecutionException, e :
ProcessingLog.addToLog(sys.exc_info()[0], ProcessingLog.LOG_ERROR)
QMessageBox.critical(None, "Error", e.msg)
progress.error(e.msg)
#QMessageBox.critical(None, "Error", e.msg)
return False
except Exception:
msg = "Error executing " + str(alg.name) + "\nSee log for more information"
msg = "Uncaught error executing " + str(alg.name) + "\nSee log for more information"
ProcessingLog.addToLog(sys.exc_info()[0], ProcessingLog.LOG_ERROR)
QMessageBox.critical(None, "Uncaught error", msg)
progress.error(e.msg)
#QMessageBox.critical(None, "Uncaught error", msg)
return False
@staticmethod

View File

@ -85,6 +85,7 @@ def getNumExportedLayers():
return numExported
def mkdir(newdir):
newdir = newdir.strip("\n\r ")
if os.path.isdir(newdir):
pass
else: