Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 20 additions & 12 deletions ruffus/drmaa_wrapper.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def __init__(self, *errmsg):
# read_stdout_stderr_from_files

#_________________________________________________________________________________________
def read_stdout_stderr_from_files( stdout_path, stderr_path, logger = None, cmd_str = "", tries=5):
def read_stdout_stderr_from_files( stdout_path, stderr_path, retain_stdout, retain_stderr, logger = None, cmd_str = "", tries=5):
"""
Reads the contents of two specified paths and returns the strings

Expand All @@ -108,7 +108,7 @@ def read_stdout_stderr_from_files( stdout_path, stderr_path, logger = None, cmd_

Logs error if files are missing: No big deal?

Cleans up files afterwards
Cleans up files afterwards, unless requested to keep them

Returns tuple of stdout and stderr.

Expand Down Expand Up @@ -140,13 +140,20 @@ def read_stdout_stderr_from_files( stdout_path, stderr_path, logger = None, cmd_
stderr = []

#
# cleanup ignoring errors
# cleanup ignoring errors, unless requested to keep them
#
try:
os.unlink( stdout_path )
os.unlink( stderr_path )
except OSError:
pass

if not retain_stdout:
try:
os.unlink( stdout_path )
except OSError:
pass

if not retain_stderr:
try:
os.unlink( stderr_path )
except OSError:
pass

return stdout, stderr

Expand Down Expand Up @@ -236,7 +243,7 @@ def write_job_script_to_temp_file( cmd_str, job_script_directory, job_name, job_
# run_job_using_drmaa

#_________________________________________________________________________________________
def run_job_using_drmaa (cmd_str, job_name = None, job_other_options = "", job_script_directory = None, job_environment = None, working_directory = None, retain_job_scripts = False, logger = None, drmaa_session = None, verbose = 0):
def run_job_using_drmaa (cmd_str, job_name = None, job_other_options = "", job_script_directory = None, job_environment = None, working_directory = None, retain_job_scripts = False, retain_stdout = False, retain_stderr = False, logger = None, drmaa_session = None, verbose = 0):

"""
Runs specified command remotely using drmaa,
Expand Down Expand Up @@ -293,7 +300,7 @@ def run_job_using_drmaa (cmd_str, job_name = None, job_other_options = "", job_s
#
# Read output
#
stdout, stderr = read_stdout_stderr_from_files( stdout_path, stderr_path, logger, cmd_str)
stdout, stderr = read_stdout_stderr_from_files( stdout_path, stderr_path, retain_stdout, retain_stderr, logger, cmd_str)


job_info_str = ("The original command was: >> %s <<\n"
Expand Down Expand Up @@ -327,7 +334,7 @@ def stderr_stdout_to_str (stderr, stdout):
% (job_info.exitStatus, job_info_str + stderr_stdout_to_str (stderr, stdout)))
elif job_info.hasExited:
if job_info.exitStatus:
raise error_drmaa_job( "The drmaa command was terminated by signal %i:\n%s"
raise error_drmaa_job( "The drmaa command exited with status %i:\n%s"
% (job_info.exitStatus, job_info_str + stderr_stdout_to_str (stderr, stdout)))
#
# Decorate normal exit with some resource usage information
Expand Down Expand Up @@ -517,6 +524,7 @@ def touch_output_files (cmd_str, output_files, logger = None):
def run_job(cmd_str, job_name = None, job_other_options = None, job_script_directory = None,
job_environment = None, working_directory = None, logger = None,
drmaa_session = None, retain_job_scripts = False,
retain_stdout = False, retain_stderr = False,
run_locally = False, output_files = None, touch_only = False, verbose = 0, local_echo = False):
"""
Runs specified command either using drmaa, or locally or only in simulation (touch the output files only)
Expand All @@ -529,4 +537,4 @@ def run_job(cmd_str, job_name = None, job_other_options = None, job_script_direc
if run_locally:
return run_job_locally (cmd_str, logger, job_environment, working_directory, local_echo)

return run_job_using_drmaa (cmd_str, job_name, job_other_options, job_script_directory, job_environment, working_directory, retain_job_scripts, logger, drmaa_session, verbose)
return run_job_using_drmaa (cmd_str, job_name, job_other_options, job_script_directory, job_environment, working_directory, retain_job_scripts, retain_stdout, retain_stderr, logger, drmaa_session, verbose)