PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/galaxy/sample_tracking/data_transfer.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 49 lines | 37 code | 5 blank | 7 comment | 7 complexity | 7c378da389d729ae8e5568634e147072 MD5 | raw file
 1import logging, sys
 2
 3class DataTransferFactory( object ):
 4    type = None
 5    def parse( self ):
 6        pass
 7
 8class ScpDataTransferFactory( DataTransferFactory ):
 9    type = 'scp'
10    def __init__( self ):
11        pass
12    def parse( self, config_file, elem ):
13        self.config = {}
14        # TODO: The 'automatic_transfer' setting is for future use.  If set to True, we will need to
15        # ensure the sample has an associated destination data library before it moves to a certain state
16        # ( e.g., Run started ).
17        self.config[ 'automatic_transfer' ] = elem.get( 'automatic_transfer' )
18        self.config[ 'host' ] = elem.get( 'host' )
19        self.config[ 'user_name' ] = elem.get( 'user_name' )
20        self.config[ 'password' ] = elem.get( 'password' )
21        self.config[ 'data_location' ] = elem.get( 'data_location' )
22        # 'rename_dataset' is optional and it may not be defined in all external types
23        # It is only used is AB SOLiD external service type for now
24        rename_dataset = elem.get( 'rename_dataset', None )
25        if rename_dataset:
26            self.config['rename_dataset'] = rename_dataset
27        # Validate
28        for name, value in self.config.items():
29            assert value, "'%s' attribute missing in 'data_transfer' element of type 'scp' in external_service_type xml config file: '%s'." % ( name, config_file )
30
31class HttpDataTransferFactory( DataTransferFactory ):
32    type = 'http'
33    def __init__( self ):
34        pass
35    def parse( self, config_file, elem ):
36        self.config = {}
37        self.config[ 'automatic_transfer' ] = elem.get( 'automatic_transfer' )
38        # Validate
39        for name, value in self.config.items():
40            assert value, "'%s' attribute missing in 'data_transfer' element of type 'http' in external_service_type xml config file: '%s'." % ( name, config_file )
41
42class FtpDataTransferFactory( DataTransferFactory ):
43    type = 'ftp'
44    def __init__( self ):
45        pass
46    def parse( self, elem ):
47        pass
48
49data_transfer_factories = dict( [ ( data_transfer.type, data_transfer() ) for data_transfer in [ ScpDataTransferFactory, HttpDataTransferFactory, FtpDataTransferFactory ] ] )