Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,8 @@ | |
__revision__ = '$Format:%H$' | ||
|
||
import os | ||
import re | ||
from qgis.core import * | ||
This comment has been minimized.
Sorry, something went wrong. |
||
from PyQt.QtGui import QIcon | ||
from processing.core.GeoAlgorithm import GeoAlgorithm | ||
from processing.gui.Help2Html import getHtmlFromHelpFile | ||
|
@@ -53,6 +55,7 @@ | |
from processing.core.outputs import OutputDirectory | ||
from processing.core.outputs import getOutputFromString | ||
from processing.script.WrongScriptException import WrongScriptException | ||
from processing.core.GeoAlgorithmExecutionException import GeoAlgorithmExecutionException | ||
|
||
pluginPath = os.path.split(os.path.dirname(__file__))[0] | ||
|
||
|
@@ -307,9 +310,6 @@ def processDescriptionParameterLine(self, line): | |
'Problem with line %d', 'ScriptAlgorithm') % (self.descriptionFile or '', line)) | ||
|
||
def processAlgorithm(self, progress): | ||
|
||
script = 'import processing\n' | ||
|
||
ns = {} | ||
ns['progress'] = progress | ||
ns['scriptDescriptionFile'] = self.descriptionFile | ||
|
@@ -320,7 +320,18 @@ def processAlgorithm(self, progress): | |
for out in self.outputs: | ||
ns[out.name] = out.value | ||
|
||
variables = re.findall("@[a-zA-Z0-9_]*", self.script) | ||
print variables | ||
script = 'import processing\n' | ||
script += self.script | ||
|
||
scope = QgsExpressionContextUtils.projectScope() | ||
This comment has been minimized.
Sorry, something went wrong.
nyalldawson
Collaborator
|
||
for var in variables: | ||
varname = var[1:] | ||
if not scope.hasVariable(varname): | ||
raise GeoAlgorithmExecutionException("Wrong variable: %s" % varname) | ||
script = script.replace(var, scope.variable(varname)) | ||
This comment has been minimized.
Sorry, something went wrong.
nyalldawson
Collaborator
|
||
|
||
exec((script), ns) | ||
for out in self.outputs: | ||
out.setValue(ns[out.name]) | ||
|
Hi victor,
can you please avoid import *
I can read you only added QgsExpressionContextUtils