From 5a2dffdf85d28cf35c367194b115f6736da2f632 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 2 Feb 2012 10:51:13 -0500 Subject: [PATCH] History export - now works for a guest user. --- lib/galaxy/tools/actions/history_imp_exp.py | 50 +++++++++++---------- 1 file changed, 26 insertions(+), 24 deletions(-) diff --git a/lib/galaxy/tools/actions/history_imp_exp.py b/lib/galaxy/tools/actions/history_imp_exp.py index 5cf0258bbf5..9b7ff0e64a7 100644 --- a/lib/galaxy/tools/actions/history_imp_exp.py +++ b/lib/galaxy/tools/actions/history_imp_exp.py @@ -9,7 +9,7 @@ log = logging.getLogger( __name__ ) class ImportHistoryToolAction( ToolAction ): """Tool action used for importing a history to an archive. """ - def execute( self, tool, trans, incoming = {}, set_output_hid = False, overwrite = True, history=None ): + def execute( self, tool, trans, incoming = {}, set_output_hid = False, overwrite = True, history=None ): # # Create job. # @@ -20,43 +20,43 @@ class ImportHistoryToolAction( ToolAction ): job.user_id = trans.user.id start_job_state = job.state #should be job.states.NEW job.state = job.states.WAITING #we need to set job state to something other than NEW, or else when tracking jobs in db it will be picked up before we have added input / output parameters - trans.sa_session.add( job ) + trans.sa_session.add( job ) trans.sa_session.flush() #ensure job.id are available - + # # Setup job and job wrapper. # - + # Add association for keeping track of job, history relationship. - - # Use abspath because mkdtemp() does not, contrary to the documentation, + + # Use abspath because mkdtemp() does not, contrary to the documentation, # always return an absolute path. archive_dir = os.path.abspath( tempfile.mkdtemp() ) jiha = trans.app.model.JobImportHistoryArchive( job=job, archive_dir=archive_dir ) trans.sa_session.add( jiha ) job_wrapper = JobImportHistoryArchiveWrapper( job ) - + # # Add parameters to job_parameter table. # - + # Set additional parameters. incoming[ '__DEST_DIR__' ] = jiha.archive_dir for name, value in tool.params_to_strings( incoming, trans.app ).iteritems(): job.add_parameter( name, value ) - + job.state = start_job_state #job inputs have been configured, restore initial job state trans.sa_session.flush() # Queue the job for execution trans.app.job_queue.put( job.id, tool ) trans.log_event( "Added import history job to the job queue, id: %s" % str(job.id), tool_id=job.tool_id ) - + return job, odict() class ExportHistoryToolAction( ToolAction ): """Tool action used for exporting a history to an archive. """ - + def execute( self, tool, trans, incoming = {}, set_output_hid = False, overwrite = True, history=None ): # # Get history to export. @@ -68,10 +68,10 @@ class ExportHistoryToolAction( ToolAction ): history = value del incoming[ history_param_name ] break - + if not history: raise Exception( 'There is no history to export.' ) - + # # Create the job and output dataset objects # @@ -79,22 +79,24 @@ class ExportHistoryToolAction( ToolAction ): job.session_id = trans.get_galaxy_session().id job.history_id = trans.history.id job.tool_id = tool.id - job.user_id = trans.user.id + if trans.user: + # If this is an actual user, run the job as that individual. Otherwise we're running as guest. + job.user_id = trans.user.id start_job_state = job.state #should be job.states.NEW job.state = job.states.WAITING #we need to set job state to something other than NEW, or else when tracking jobs in db it will be picked up before we have added input / output parameters trans.sa_session.add( job ) - + # Create dataset that will serve as archive. archive_dataset = trans.app.model.Dataset() trans.sa_session.add( archive_dataset ) - + trans.sa_session.flush() #ensure job.id and archive_dataset.id are available trans.app.object_store.create( archive_dataset ) # set the object store id, create dataset (if applicable) - + # # Setup job and job wrapper. # - + # Add association for keeping track of job, history, archive relationship. jeha = trans.app.model.JobExportHistoryArchive( job=job, history=history, \ dataset=archive_dataset, \ @@ -104,23 +106,23 @@ class ExportHistoryToolAction( ToolAction ): job_wrapper = JobExportHistoryArchiveWrapper( job ) cmd_line = job_wrapper.setup_job( trans, jeha, include_hidden=incoming[ 'include_hidden' ], \ include_deleted=incoming[ 'include_deleted' ] ) - + # # Add parameters to job_parameter table. # - + # Set additional parameters. incoming[ '__HISTORY_TO_EXPORT__' ] = history.id incoming[ '__EXPORT_HISTORY_COMMAND_INPUTS_OPTIONS__' ] = cmd_line for name, value in tool.params_to_strings( incoming, trans.app ).iteritems(): job.add_parameter( name, value ) - + job.state = start_job_state #job inputs have been configured, restore initial job state trans.sa_session.flush() - - + + # Queue the job for execution trans.app.job_queue.put( job.id, tool ) trans.log_event( "Added export history job to the job queue, id: %s" % str(job.id), tool_id=job.tool_id ) - + return job, odict()