Commit a5a5ba76 authored by Rashad Kanavath's avatar Rashad Kanavath
Browse files

fix executeOtb method to run otbalgorithms

parent 86f0377b
......@@ -54,26 +54,39 @@ def geoidFile():
def executeOtb(commands, feedback, addToLog=True):
loglines = []
loglines.append(tr("OTB execution console output"))
os.putenv('ITK_AUTOLOAD_PATH', otbLibPath())
#loglines.append(tr("OTB execution console output\n"))
fused_command = ''.join(['"%s" ' % re.sub(r'^"|"$', '', c) for c in commands])
with subprocess.Popen(fused_command, shell=True, stdout=subprocess.PIPE, stdin=subprocess.DEVNULL, stderr=subprocess.STDOUT, universal_newlines=True) as proc:
if isMac(): # This trick avoids having an uninterrupted system call exception if OTB is not installed
time.sleep(1)
for line in iter(proc.stdout.readline, ""):
if "[*" in line:
idx = line.find("[*")
perc = int(line[idx - 4:idx - 2].strip(" "))
if perc != 0:
feedback.setProgress(perc)
else:
loglines.append(line)
feedback.pushConsoleInfo(line)
with subprocess.Popen(
commands,
shell=True,
stdout=subprocess.PIPE,
stdin=subprocess.DEVNULL,
stderr=subprocess.STDOUT,
universal_newlines=True
) as proc:
try:
for line in iter(proc.stdout.readline, ''):
if 'Writing' in line:
perc = line.split(':')[1]
perc = perc.split('%')[0]
s = ''.join([x for x in perc[1] if x.isdigit()])
try:
if int(s) >= 100:
feedback.pushConsoleInfo(line)
feedback.setProgress(int(s))
if addToLog:
ProcessingLog.addToLog(ProcessingLog.LOG_INFO, loglines)
except:
pass
else:
line = line.strip()
if line != '/' and line != '-' and line != '\\' and line != '|':
loglines.append(line)
feedback.pushConsoleInfo(line)
except:
pass
return loglines
if feedback is None:
QgsMessageLog.logMessage('\n'.join(loglines), 'Processing', Qgis.Info)
def tr(string, context=''):
if context == '':
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment