[GRASS-SVN] r49012 -
grass/branches/develbranch_6/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Sun Oct 30 17:25:04 EDT 2011
Author: martinl
Date: 2011-10-30 14:25:04 -0700 (Sun, 30 Oct 2011)
New Revision: 49012
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
Log:
wxGUI/modeler: fix variable substitution
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py 2011-10-30 20:39:07 UTC (rev 49011)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py 2011-10-30 21:25:04 UTC (rev 49012)
@@ -396,7 +396,7 @@
pattern = re.compile(r'(.*)(%.+\s?)(.*)')
for action in self.GetItems(objType = ModelAction):
- cmd = action.GetLog(string = False, substitute = True)
+ cmd = action.GetLog(string = False, substitute = self.GetVariables())
task = menuform.GUI(show = None).ParseCommand(cmd = cmd)
errList += map(lambda x: cmd[0] + ': ' + x, task.get_cmd_error())
@@ -481,7 +481,7 @@
else:
self.fileInput[finput] = None
- log.RunCmd(command = item.GetLog(string = False, substitute = True),
+ log.RunCmd(command = item.GetLog(string = False, substitute = params),
onDone = onDone)
if name in params:
@@ -552,12 +552,6 @@
if err:
GError(parent = parent, message = unicode('\n'.join(err)))
return
-
- # get variable values
- varValue = dict()
- if 'variables' in params:
- for var in params['variables']['params']:
- varValue[var['name']] = var['value']
log.cmdThread.SetId(-1)
for item in self.GetItems():
@@ -575,11 +569,18 @@
pattern = re.compile('%' + variable)
if pattern.search(cond):
value = ''
- if variable in varValue:
- value = varValue[variable]
+ if params and 'variables' in params:
+ for p in params['variables']['params']:
+ if variable == p.get('name', ''):
+ value = p.get('value', '')
+ break
+
if not value:
value = variables[variable].get('value', '')
+ if not value:
+ continue
+
vtype = variables[variable].get('type', 'string')
if vtype == 'string':
value = '"' + value + '"'
@@ -600,21 +601,23 @@
else:
vlist = eval(condText)
+ if 'variables' not in params:
+ params['variables'] = { 'params' : [] }
+ varDict = { 'name' : condVar, 'value' : '' }
+ params['variables']['params'].append(varDict)
+
for var in vlist:
for action in item.GetItems():
if not isinstance(action, ModelAction) or \
not action.IsEnabled():
continue
-
- par = action.GetParams(dcopy = True)['params']
- for idx in range(len(par)):
- if not par[idx].get('value', None):
- continue
-
- if pattern.search(par[idx]['value']):
- par[idx]['value'] = pattern.sub(var, par[idx]['value'])
- self.RunAction(action, { action.GetName(): {'params': par } }, log, onDone)
-
+
+ varDict['value'] = var
+
+ self.RunAction(item = action, params = params,
+ log = log, onDone = onDone)
+ params['variables']['params'].remove(varDict)
+
# discard values
if params:
for item in params.itervalues():
@@ -1880,36 +1883,38 @@
"""!Get properties dialog"""
return self.propWin
- def GetLog(self, string = True, substitute = False):
+ def GetLog(self, string = True, substitute = None):
"""!Get logging info
@param string True to get cmd as a string otherwise a list
- @param substitute True to substitute variables
+ @param substitute dictionary of parameter to substitute or None
"""
cmd = self.task.get_cmd(ignoreErrors = True, ignoreRequired = True,
ignoreDefault = False)
# substitute variables
if substitute:
- variables = self.parent.GetVariables()
- fparams = self.parent.GetVariables(params = True)
- params = None
- for values in fparams.itervalues():
- params = values['params']
- break
-
+ variables = []
+ if 'variables' in substitute:
+ for p in substitute['variables']['params']:
+ variables.append(p.get('name', ''))
+ else:
+ variables = self.parent.GetVariables()
for variable in variables:
pattern= re.compile('%' + variable)
value = ''
- if params:
- for p in params:
+ if substitute and 'variables' in substitute:
+ for p in substitute['variables']['params']:
if variable == p.get('name', ''):
value = p.get('value', '')
break
-
+
if not value:
value = variables[variable].get('value', '')
+ if not value:
+ continue
+
for idx in range(len(cmd)):
if pattern.search(cmd[idx]):
cmd[idx] = pattern.sub(value, cmd[idx])
More information about the grass-commit
mailing list