[hg] galaxy 3360: LIMS: replaced os.system with subprocess to sp...
details: http://www.bx.psu.edu/hg/galaxy/rev/b4c811246b1d changeset: 3360:b4c811246b1d user: rc date: Tue Feb 09 11:21:53 2010 -0500 description: LIMS: replaced os.system with subprocess to spawn the data transfer daemon process diffstat: lib/galaxy/web/controllers/forms.py | 2 +- lib/galaxy/web/controllers/requests_admin.py | 42 +++++++++++++++++------ scripts/galaxy_messaging/server/daemon.py | 2 +- scripts/galaxy_messaging/server/data_transfer.py | 13 ++++-- 4 files changed, 40 insertions(+), 19 deletions(-) diffs (145 lines): diff -r 185eab051284 -r b4c811246b1d lib/galaxy/web/controllers/forms.py --- a/lib/galaxy/web/controllers/forms.py Tue Feb 09 04:16:26 2010 -0500 +++ b/lib/galaxy/web/controllers/forms.py Tue Feb 09 11:21:53 2010 -0500 @@ -137,7 +137,7 @@ msg=msg, messagetype='error', name=util.restore_text( params.get( 'name', '' ) ), - description=util.restore_text( params.get( 'description', '' ) ) ) ) + description=util.restore_text( params.get( 'description', '' ) ) )) self.__get_saved_form( fd ) if self.__imported_from_file: return trans.response.send_redirect( web.url_for( controller='forms', diff -r 185eab051284 -r b4c811246b1d lib/galaxy/web/controllers/requests_admin.py --- a/lib/galaxy/web/controllers/requests_admin.py Tue Feb 09 04:16:26 2010 -0500 +++ b/lib/galaxy/web/controllers/requests_admin.py Tue Feb 09 11:21:53 2010 -0500 @@ -4,7 +4,7 @@ from galaxy.datatypes import sniff from galaxy import util from galaxy.util.streamball import StreamBall -import logging, tempfile, zipfile, tarfile, os, sys +import logging, tempfile, zipfile, tarfile, os, sys, subprocess from galaxy.web.form_builder import * from datetime import datetime, timedelta from galaxy.web.controllers.forms import get_all_forms @@ -1526,31 +1526,49 @@ sample_id=trans.security.encode_id(sample.id), messagetype='error', msg=msg)) + error_msg = '' transfer_script = "scripts/galaxy_messaging/server/daemon.py" for index, dataset in enumerate(sample.dataset_files): dfile = dataset[0] status = dataset[1] if status == sample.transfer_status.NOT_STARTED: - cmd = "python %s %s %s %s %s %s %s %s %s" % ( transfer_script, - datatx_info['host'], - datatx_info['username'], - datatx_info['password'], - dfile, - sample.id, - index, - trans.security.encode_id(sample.library.id), - trans.security.encode_id(sample.folder.id)) + cmd = ( "python", + transfer_script, + datatx_info['host'], + datatx_info['username'], + datatx_info['password'], + dfile, + str(sample.id), + str(index), + trans.security.encode_id(sample.library.id), + trans.security.encode_id(sample.folder.id) ) # set the transfer status sample.dataset_files[index][1] = sample.transfer_status.IN_PROGRESS trans.sa_session.add( sample ) trans.sa_session.flush() - os.system(cmd) + try: + retcode = subprocess.call(cmd) + except Exception, e: + error_msg = dfile.split('/')[-1] + ": Data transfer failed. " + str(e) + "<br/>" + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='show_datatx_page', + sample_id=trans.security.encode_id(sample.id), + folder_path=os.path.dirname(dfile), + messagetype='error', + msg=error_msg)) # set the sample state to the last state if sample.current_state().id != sample.request.type.states[-1].id: event = trans.app.model.SampleEvent(sample, sample.request.type.states[-1], - 'The dataset are ready & are being transfered to Galaxy') + 'The dataset is ready and are being transfered to Galaxy') trans.sa_session.add( event ) trans.sa_session.flush() + if error_msg: + return trans.response.send_redirect( web.url_for( controller='requests_admin', + action='show_datatx_page', + sample_id=trans.security.encode_id(sample.id), + folder_path=os.path.dirname(dfile), + messagetype='error', + msg=error_msg)) return trans.response.send_redirect( web.url_for( controller='requests_admin', action='show_datatx_page', sample_id=trans.security.encode_id(sample.id), diff -r 185eab051284 -r b4c811246b1d scripts/galaxy_messaging/server/daemon.py --- a/scripts/galaxy_messaging/server/daemon.py Tue Feb 09 04:16:26 2010 -0500 +++ b/scripts/galaxy_messaging/server/daemon.py Tue Feb 09 11:21:53 2010 -0500 @@ -29,6 +29,6 @@ sys.exit(0) # Exit first parent. except OSError, e: sys.stderr.write("fork #1 failed: (%d) %sn" % (e.errno, e.strerror)) - sys.exit(1) + sys.exit(2) os.execv(os.path.join( os.getcwd(), "scripts/galaxy_messaging/server/data_transfer.py"), sys.argv) diff -r 185eab051284 -r b4c811246b1d scripts/galaxy_messaging/server/data_transfer.py --- a/scripts/galaxy_messaging/server/data_transfer.py Tue Feb 09 04:16:26 2010 -0500 +++ b/scripts/galaxy_messaging/server/data_transfer.py Tue Feb 09 11:21:53 2010 -0500 @@ -41,8 +41,8 @@ curr_dir = os.getcwd() logfile = os.path.join(curr_dir, 'data_transfer.log') -logging.basicConfig(filename=logfile, level=logging.DEBUG, - format="%(asctime)s [%(levelname)s] %(message)s") +logging.basicConfig(filename=sys.stdout, level=logging.DEBUG, + format="%(asctime)s [%(levelname)s] %(message)s") class DataTransferException(Exception): def __init__(self, value): @@ -137,7 +137,9 @@ timeout=10) logging.debug(output) if not os.path.exists(os.path.join(self.server_dir, os.path.basename(self.remote_file))): - raise Exception + raise DataTransferException('Could not find the local file after transfer (%s)' % os.path.join(self.server_dir, os.path.basename(self.remote_file))) + except DataTransferException, (e): + self.error_and_exit(e.msg) except: self.error_and_exit() @@ -192,6 +194,8 @@ raise DataTransferException("The "+email+" user could not logout of Galaxy") except DataTransferException, (e): self.error_and_exit(e.msg) + except: + self.error_and_exit() def update_status(self, status): ''' @@ -202,7 +206,6 @@ df = from_json_string(galaxy.get_sample_dataset_files(self.sample_id)) logging.debug(df) df[self.dataset_index][1] = status - galaxy.set_sample_dataset_files(self.sample_id, to_json_string(df)) logging.debug("######################\n"+str(from_json_string(galaxy.get_sample_dataset_files(self.sample_id))[self.dataset_index])) except: @@ -219,5 +222,5 @@ dt = DataTransfer(sys.argv[1], sys.argv[2], sys.argv[3], sys.argv[4], int(sys.argv[5]), int(sys.argv[6]), sys.argv[7], sys.argv[8]) dt.start() + sys.exit(0) -
participants (1)
-
Nate Coraor