PageRenderTime 17ms CodeModel.GetById 2ms app.highlight 11ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/sample_tracking/request_types.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 30 lines | 23 code | 2 blank | 5 comment | 2 complexity | 648fd27235cc7d2ed9cf84feac3c1f49 MD5 | raw file
 1"""
 2RequestType
 3"""
 4import logging
 5from galaxy.model import RequestType
 6from sample import sample_state_factory
 7
 8RENAME_DATASET_OPTIONS = dict( [ ( f_type.lower(), f_descript ) for f_type, f_descript in RequestType.rename_dataset_options.items() ] )
 9
10class RequestTypeFactory( object ):
11    def __init__( self, sample_state_factory, rename_dataset_options ):
12        self.sample_state_factory = sample_state_factory
13        self.rename_dataset_options = rename_dataset_options
14    def new( self, name, request_form, sample_form, external_service, description=None, sample_states = None ):
15        """Return new RequestType."""
16        assert name, 'RequestType requires a name'
17        return RequestType( name=name, desc=description, request_form=request_form, sample_form=sample_form, external_service=external_service )
18    def from_elem( self, elem, request_form, sample_form, external_service ):
19        """Return RequestType created from an xml string."""
20        name = elem.get( 'name', '' )
21        description = elem.get( 'description', '' )
22        rval = self.new( name, request_form, sample_form, external_service=external_service, description=description )
23        #load states
24        sample_states_elem = elem.find( 'sample_states' )
25        if sample_states_elem:
26            for sample_state_elem in sample_states_elem.findall( 'state' ):
27                sample_state = self.sample_state_factory.from_elem( rval, sample_state_elem )
28        return rval
29
30request_type_factory = RequestTypeFactory( sample_state_factory, RENAME_DATASET_OPTIONS )