@@ -128,28 +128,28 @@ def getSagaInstalledVersion(runSaga=False):
128
128
# (python docs advices to use subprocess32 instead of python2.7's subprocess)
129
129
commands = ["saga_cmd -v" ]
130
130
while retries < maxRetries :
131
- proc = subprocess .Popen (
131
+ with subprocess .Popen (
132
132
commands ,
133
133
shell = True ,
134
134
stdout = subprocess .PIPE ,
135
135
stdin = subprocess .DEVNULL ,
136
136
stderr = subprocess .STDOUT ,
137
137
universal_newlines = True ,
138
- ). stdout
139
- if isMac (): # This trick avoids having an uninterrupted system call exception if SAGA is not installed
140
- time .sleep (1 )
141
- try :
142
- lines = proc .readlines ()
143
- for line in lines :
144
- if line .startswith ("SAGA Version:" ):
145
- _installedVersion = line [len ("SAGA Version:" ):].strip ().split (" " )[0 ]
146
- _installedVersionFound = True
147
- return _installedVersion
148
- return None
149
- except IOError :
150
- retries += 1
151
- except :
152
- return None
138
+ ) as proc :
139
+ if isMac (): # This trick avoids having an uninterrupted system call exception if SAGA is not installed
140
+ time .sleep (1 )
141
+ try :
142
+ lines = proc . stdout .readlines ()
143
+ for line in lines :
144
+ if line .startswith ("SAGA Version:" ):
145
+ _installedVersion = line [len ("SAGA Version:" ):].strip ().split (" " )[0 ]
146
+ _installedVersionFound = True
147
+ return _installedVersion
148
+ return None
149
+ except IOError :
150
+ retries += 1
151
+ except :
152
+ return None
153
153
154
154
return _installedVersion
155
155
@@ -163,28 +163,29 @@ def executeSaga(progress):
163
163
command = [sagaBatchJobFilename ()]
164
164
loglines = []
165
165
loglines .append (QCoreApplication .translate ('SagaUtils' , 'SAGA execution console output' ))
166
- proc = subprocess .Popen (
166
+ with subprocess .Popen (
167
167
command ,
168
168
shell = True ,
169
169
stdout = subprocess .PIPE ,
170
170
stdin = subprocess .DEVNULL ,
171
171
stderr = subprocess .STDOUT ,
172
172
universal_newlines = True ,
173
- ).stdout
174
- try :
175
- for line in iter (proc .readline , '' ):
176
- if '%' in line :
177
- s = '' .join ([x for x in line if x .isdigit ()])
178
- try :
179
- progress .setPercentage (int (s ))
180
- except :
181
- pass
182
- else :
183
- line = line .strip ()
184
- if line != '/' and line != '-' and line != '\\ ' and line != '|' :
185
- loglines .append (line )
186
- progress .setConsoleInfo (line )
187
- except :
188
- pass
173
+ ) as proc :
174
+ try :
175
+ for line in iter (proc .stdout .readline , '' ):
176
+ if '%' in line :
177
+ s = '' .join ([x for x in line if x .isdigit ()])
178
+ try :
179
+ progress .setPercentage (int (s ))
180
+ except :
181
+ pass
182
+ else :
183
+ line = line .strip ()
184
+ if line != '/' and line != '-' and line != '\\ ' and line != '|' :
185
+ loglines .append (line )
186
+ progress .setConsoleInfo (line )
187
+ except :
188
+ pass
189
+
189
190
if ProcessingConfig .getSetting (SAGA_LOG_CONSOLE ):
190
191
ProcessingLog .addToLog (ProcessingLog .LOG_INFO , loglines )
0 commit comments