Ver código fonte

wxGUI/modeler: improve validity check (variable substitution)

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@48934 15284696-431f-4ddb-bdfa-cd5b030d7da7
Martin Landa 13 anos atrás
pai
commit
4702a05bab
1 arquivos alterados com 13 adições e 3 exclusões
  1. 13 3
      gui/wxpython/gui_modules/gmodeler.py

+ 13 - 3
gui/wxpython/gui_modules/gmodeler.py

@@ -392,6 +392,8 @@ class Model(object):
         """!Validate model, return None if model is valid otherwise
         error string"""
         errList = list()
+
+        pattern = re.compile(r'(.*)(%.+\s?)(.*)')
         for action in self.GetItems(objType = ModelAction):
             cmd = action.GetLog(string = False, substitute = True)
             
@@ -402,8 +404,16 @@ class Model(object):
                 if '=' not in opt:
                     continue
                 key, value = opt.split('=', 1)
-                if '%' in value:
-                    errList.append(_("%s: undefined variable '%s'") % (cmd[0], value.strip()))
+                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))
         
         return errList
 
@@ -4862,7 +4872,7 @@ if __name__ == "__main__":
             variables = self.model.GetVariables()
             cond = item.GetText()
             for variable in variables:
-                pattern= re.compile('%' + variable)
+                pattern = re.compile('%' + variable)
                 if pattern.search(cond):
                     value = variables[variable].get('value', '')
                     if variables[variable].get('type', 'string') == 'string':