root/galaxy-central/lib/galaxy/tools/actions/history_imp_exp.py @ 2

リビジョン 2, 3.1 KB (コミッタ: hatakeyama, 14 年 前)

import galaxy-central

行番号 
1from __init__ import ToolAction
2from galaxy.util.odict import odict
3from galaxy.tools.imp_exp import JobExportHistoryArchiveWrapper
4
5import logging
6log = logging.getLogger( __name__ )
7
8class ExportHistoryToolAction( ToolAction ):
9    """Tool action used for exporting a history to an archive. """
10   
11    def execute( self, tool, trans, incoming = {}, set_output_hid = False, overwrite = True ):
12        #
13        # Get history to export.
14        #
15        history = None
16        for name, value in incoming.iteritems():
17            if isinstance( value, trans.app.model.History ):
18                history_param_name = name
19                history = value
20                del incoming[ history_param_name ]
21                break
22               
23        if not history:
24            raise Exception( 'There is no history to export.' )
25       
26        #
27        # Create the job and output dataset objects
28        #
29        job = trans.app.model.Job()
30        job.session_id = trans.get_galaxy_session().id
31        job.history_id = trans.history.id
32        job.tool_id = tool.id
33        start_job_state = job.state #should be job.states.NEW
34        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
35        trans.sa_session.add( job )
36       
37        # Create dataset that will serve as archive.
38        archive_dataset = trans.app.model.Dataset()
39        trans.sa_session.add( archive_dataset )
40       
41       
42        trans.sa_session.flush() #ensure job.id and archive_dataset.id are available
43       
44        #
45        # Setup job and job wrapper.
46        #
47       
48        # Add association for keeping track of job, history, archive relationship.
49        jeha = trans.app.model.JobExportHistoryArchive( job=job, history=history, \
50                                                        dataset=archive_dataset, \
51                                                        compressed=incoming[ 'compress' ] )
52        trans.sa_session.add( jeha )
53
54        job_wrapper = JobExportHistoryArchiveWrapper( job )
55        cmd_line = job_wrapper.setup_job( trans, jeha, include_hidden=incoming[ 'include_hidden' ], \
56                                            include_deleted=incoming[ 'include_deleted' ] )
57       
58        #
59        # Add parameters to job_parameter table.
60        #
61       
62        # Set additional parameters.
63        incoming[ '__HISTORY_TO_EXPORT__' ] = history.id
64        incoming[ '__EXPORT_HISTORY_COMMAND_INPUTS_OPTIONS__' ] = cmd_line
65        for name, value in tool.params_to_strings( incoming, trans.app ).iteritems():
66            job.add_parameter( name, value )
67           
68        job.state = start_job_state #job inputs have been configured, restore initial job state
69        trans.sa_session.flush()
70       
71       
72        # Queue the job for execution
73        trans.app.job_queue.put( job.id, tool )
74        trans.log_event( "Added export history job to the job queue, id: %s" % str(job.id), tool_id=job.tool_id )
75               
76        return job, odict()
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。