Skip to content
Permalink
Browse files

[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
  • Loading branch information
volaya committed Sep 23, 2013
1 parent c55c2ab commit e4c60adcd388a890cb3b23df93ee3e4c7049f879
@@ -16,6 +16,7 @@
* *
***************************************************************************
"""
import sys

__author__ = 'Victor Olaya'
__date__ = 'August 2012'
@@ -71,11 +72,16 @@ def addProvider(provider, updateList = False):
'''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):
@@ -96,7 +96,7 @@ def __init__(self, alg, mainWidget):
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 @@ def accept(self):
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 @@ def finish(self):
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 @@ def error(self, msg):
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 @@ def cancel(self):
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>')
@@ -26,6 +26,7 @@
import pickle
from processing.tools.system import *
import os
import codecs

class Help2Html():

@@ -39,7 +40,7 @@ def getHtmlFile(self, alg, helpFile):
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 @@ def getHtmlFile(self, alg, helpFile):
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

@@ -46,12 +46,14 @@ def runalg(alg, progress):
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
@@ -85,6 +85,7 @@ def getNumExportedLayers():
return numExported

def mkdir(newdir):
newdir = newdir.strip("\n\r ")
if os.path.isdir(newdir):
pass
else:

0 comments on commit e4c60ad

Please sign in to comment.
You can’t perform that action at this time.