|
@@ -394,12 +394,14 @@ class Model(object):
|
|
|
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 @@ class Model(object):
|
|
|
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
|
|
|
- """
|
|
|
- name = item.GetName()
|
|
|
- if name in params:
|
|
|
- paramsOrig = item.GetParams(dcopy = True)
|
|
|
- item.MergeParams(params[name])
|
|
|
+ @param checkOnly tuble - True to check variable, don't touch files
|
|
|
|
|
|
- if statusbar:
|
|
|
- statusbar.SetStatusText(_('Running model...'), 0)
|
|
|
+ @return list of undefined variables
|
|
|
+ """
|
|
|
+ errList = list()
|
|
|
|
|
|
+ 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 @@ class Model(object):
|
|
|
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,28 +458,61 @@ class Model(object):
|
|
|
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)
|