Newer
Older
Javier Vegas-Regidor
committed
import os
from autosubmit.config.log import Log
Javier Vegas-Regidor
committed
"""
Class to run CDFTools executables
"""
Javier Vegas-Regidor
committed
def __init__(self, path=''):
self.path = path
def run(self, command, input, output=None, options=None, log_level=Log.INFO):
"""
Runs one of the CDFTools
:param command: executable to run
:param output: output file. Not all tools support this parameter
:param options: options for the tool.
:param log_level: log level at which the output of the cdftool command will be added
Javier Vegas-Regidor
committed
line = [os.path.join(self.path, command)]
if not os.path.exists(line[0]):
raise Exception('Error executing {0}\n Command does not exist in {1}', command, self.path)
Javier Vegas-Regidor
committed
if input:
if not os.path.exists(input):
raise Exception('Error executing {0}\n Input file {1} file does not exist', command, input)
if not os.path.exists(element):
raise Exception('Error executing {0}\n Input file {1} file does not exist', command, element)
Javier Vegas-Regidor
committed
if options:
if isinstance(options, basestring):
options = options.split()
Javier Vegas-Regidor
committed
for option in options:
Javier Vegas-Regidor
committed
if output:
if input == output:
raise Exception('Input and output file can not be the same on CDFTools')
Javier Vegas-Regidor
committed
line.append('-o')
line.append(output)
Log.debug('Executing {0}', ' '.join(line))
shell_output = Utils.execute_shell_command(line, log_level)
if output:
if not os.path.exists(output):
raise Exception('Error executing {0}\n Output file not created', ' '.join(line))