Skip to content

Commit

Permalink
add optional flag for suppressing exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
wtbarnes committed Jun 20, 2022
1 parent 8653799 commit ad99f41
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions hissw/environment.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ def shell_script(self, command_filename):
'command_filename': command_filename}
return self.env.get_template('startup.sh').render(**params)

def run(self, script, args=None, save_vars=None, verbose=True):
def run(self, script, args=None, save_vars=None, verbose=True, **kwargs):
"""
Set up the SSWIDL environment and run the supplied scripts.
Expand Down Expand Up @@ -179,22 +179,23 @@ def run(self, script, args=None, save_vars=None, verbose=True):
subprocess.call(['chmod', 'u+x', shell_filename])
cmd_output = subprocess.run([shell_filename], shell=True, stderr=subprocess.PIPE,
stdout=subprocess.PIPE)
self._check_for_errors(cmd_output, verbose)
self._check_for_errors(cmd_output, verbose, **kwargs)
results = readsav(save_filename)

return results

def _check_for_errors(self, output, verbose):
def _check_for_errors(self, output, verbose, **kwargs):
"""
Check IDL output to try and decide if an error has occurred
"""
stdout = output.stdout.decode('utf-8')
stderr = output.stderr.decode('utf-8')
# NOTE: For some reason, not only errors are output to stderr so we
# have to check it for certain keywords to see if an error occurred
if 'execution halted' in stderr.lower():
raise SSWIDLError(stderr)
if 'failed to acquire license' in stderr.lower():
raise IDLLicenseError(stderr)
if kwargs.get('raise_exceptions', True):
if 'execution halted' in stderr.lower():
raise SSWIDLError(stderr)
if 'failed to acquire license' in stderr.lower():
raise IDLLicenseError(stderr)
if verbose:
print(f'{stderr}\n{stdout}')

0 comments on commit ad99f41

Please sign in to comment.