[GRASS-SVN] r49039 -
grass/branches/develbranch_6/gui/wxpython/gui_modules
svn_grass at osgeo.org
svn_grass at osgeo.org
Tue Nov 1 11:19:42 EDT 2011
Author: martinl
Date: 2011-11-01 08:19:41 -0700 (Tue, 01 Nov 2011)
New Revision: 49039
Modified:
grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
Log:
wxGUI/modeler: better check for substituting variables
Modified: grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py
===================================================================
--- grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py 2011-11-01 13:20:06 UTC (rev 49038)
+++ grass/branches/develbranch_6/gui/wxpython/gui_modules/gmodeler.py 2011-11-01 15:19:41 UTC (rev 49039)
@@ -394,12 +394,14 @@
error string"""
errList = list()
+ variables = self.GetVariables().keys()
pattern = re.compile(r'(.*)(%.+\s?)(.*)')
for action in self.GetItems(objType = ModelAction):
- cmd = action.GetLog(string = False, substitute = self.GetVariables())
+ cmd = action.GetLog(string = False)
task = menuform.GUI(show = None).ParseCommand(cmd = cmd)
errList += map(lambda x: cmd[0] + ': ' + x, task.get_cmd_error())
+
# check also variables
for opt in cmd[1:]:
if '=' not in opt:
@@ -408,35 +410,33 @@
sval = pattern.search(value)
if sval:
var = sval.group(2).strip()[1:] # ignore '%'
- report = True
- for item in filter(lambda x: isinstance(x, ModelLoop), action.GetBlock()):
- if var in item.GetText():
- report = False
- break
- if report:
- errList.append(_("%s: undefined variable '%s'") % (cmd[0], var))
+ if var not in variables:
+ report = True
+ for item in filter(lambda x: isinstance(x, ModelLoop), action.GetBlock()):
+ if var in item.GetText():
+ report = False
+ break
+ if report:
+ errList.append(_("%s: undefined variable '%s'") % (cmd[0], var))
+ errList += self._substituteFile(action, checkOnly = True)
+
return errList
- def RunAction(self, item, params, log, onDone, statusbar = None):
- """!Run given action
+ def _substituteFile(self, item, params = None, checkOnly = False):
+ """!Subsitute variables in command file inputs
- @param item action item
- @param params parameters dict
- @param log logging window
- @param onDone on-done method
- @param statusbar wx.StatusBar instance or None
+ @param checkOnly tuble - True to check variable, don't touch files
+
+ @return list of undefined variables
"""
- name = item.GetName()
- if name in params:
- paramsOrig = item.GetParams(dcopy = True)
- item.MergeParams(params[name])
+ errList = list()
- if statusbar:
- statusbar.SetStatusText(_('Running model...'), 0)
-
+ if not hasattr(self, "fileInput"):
+ self.fileInput = dict()
+
# collect ascii inputs
- self.fileInput = dict()
+ cmdFileInput = list()
for p in item.GetParams()['params']:
if p.get('element', '') == 'file' and \
p.get('prompt', '') == 'input' and \
@@ -444,9 +444,9 @@
filename = p.get('value', p.get('default', ''))
if filename and \
mimetypes.guess_type(filename)[0] == 'text/plain':
- self.fileInput[filename] = None
+ cmdFileInput.append(filename)
- for finput in self.fileInput:
+ for finput in cmdFileInput:
# read lines
fd = open(finput, "r")
try:
@@ -458,29 +458,62 @@
write = False
variables = self.GetVariables()
for variable in variables:
- pattern= re.compile('%' + variable)
+ pattern = re.compile('%' + variable)
value = ''
if params and 'variables' in params:
for p in params['variables']['params']:
if variable == p.get('name', ''):
- value = p.get('value', '')
+ if p.get('type', 'string') == 'string':
+ value = p.get('value', '')
+ else:
+ value = str(p.get('value', ''))
break
if not value:
value = variables[variable].get('value', '')
data = pattern.sub(value, data)
- write = True
+ if not checkOnly:
+ write = True
- if write:
- fd = open(finput, "w")
- try:
- fd.write(data)
- finally:
- fd.close()
- else:
- self.fileInput[finput] = None
+ pattern = re.compile(r'(.*)(%.+\s?)(.*)')
+ sval = pattern.search(data)
+ if sval:
+ var = sval.group(2).strip()[1:] # ignore '%'
+ cmd = item.GetLog(string = False)[0]
+ errList.append(_("%s: undefined variable '%s'") % (cmd, var))
+
+ if not checkOnly:
+ if write:
+ fd = open(finput, "w")
+ try:
+ fd.write(data)
+ finally:
+ fd.close()
+ else:
+ self.fileInput[finput] = None
+
+ return errList
+
+ def RunAction(self, item, params, log, onDone, statusbar = None):
+ """!Run given action
+
+ @param item action item
+ @param params parameters dict
+ @param log logging window
+ @param onDone on-done method
+ @param statusbar wx.StatusBar instance or None
+ """
+ name = item.GetName()
+ if name in params:
+ paramsOrig = item.GetParams(dcopy = True)
+ item.MergeParams(params[name])
+ if statusbar:
+ statusbar.SetStatusText(_('Running model...'), 0)
+
+ self._substituteFile(item, params)
+
log.RunCmd(command = item.GetLog(string = False, substitute = params),
onDone = onDone)
More information about the grass-commit
mailing list