@@ -12,7 +12,7 @@ class ConfigurationError( Exception ):
12
12
pass
13
13
14
14
class Registry ( object ):
15
- def __init__ ( self , root_dir = None , config = None ):
15
+ def __init__ ( self ):
16
16
self .log = logging .getLogger (__name__ )
17
17
self .log .addHandler ( logging .NullHandler () )
18
18
self .datatypes_by_extension = {}
@@ -27,21 +27,33 @@ def __init__( self, root_dir=None, config=None ):
27
27
self .sniff_order = []
28
28
self .upload_file_formats = []
29
29
self .display_applications = odict () #map a display application id to a display application
30
- inherit_display_application_by_class = []
30
+ self .datatype_converters_path = None
31
+ self .datatype_indexers_path = None
32
+ self .display_applications_path = None
33
+ def load_datatypes ( self , root_dir = None , config = None , imported_module = None ):
31
34
if root_dir and config :
35
+ inherit_display_application_by_class = []
32
36
# Parse datatypes_conf.xml
33
37
tree = galaxy .util .parse_xml ( config )
34
38
root = tree .getroot ()
35
39
# Load datatypes and converters from config
36
40
self .log .debug ( 'Loading datatypes from %s' % config )
37
41
registration = root .find ( 'registration' )
38
- self .datatype_converters_path = os .path .join ( root_dir , registration .get ( 'converters_path' , 'lib/galaxy/datatypes/converters' ) )
39
- self .datatype_indexers_path = os .path .join ( root_dir , registration .get ( 'indexers_path' , 'lib/galaxy/datatypes/indexers' ) )
40
- self .display_applications_path = os .path .join ( root_dir , registration .get ( 'display_path' , 'display_applications' ) )
41
- if not os .path .isdir ( self .datatype_converters_path ):
42
- raise ConfigurationError ( "Directory does not exist: %s" % self .datatype_converters_path )
43
- if not os .path .isdir ( self .datatype_indexers_path ):
44
- raise ConfigurationError ( "Directory does not exist: %s" % self .datatype_indexers_path )
42
+ # The following implementation implies that only the first datatypes_conf.xml parsed will
43
+ # define the various paths. This is probably ok, since we can justifiably require that the
44
+ # local datatypes_conf.xml file sets the standard, and all additional datatypes_conf.xml
45
+ # files installed with repositories from tool sheds must use the same paths. However, we
46
+ # may discover at some future time that allowing for multiple paths is more optimal.
47
+ if not self .datatype_converters_path :
48
+ self .datatype_converters_path = os .path .join ( root_dir , registration .get ( 'converters_path' , 'lib/galaxy/datatypes/converters' ) )
49
+ if not os .path .isdir ( self .datatype_converters_path ):
50
+ raise ConfigurationError ( "Directory does not exist: %s" % self .datatype_converters_path )
51
+ if not self .datatype_indexers_path :
52
+ self .datatype_indexers_path = os .path .join ( root_dir , registration .get ( 'indexers_path' , 'lib/galaxy/datatypes/indexers' ) )
53
+ if not os .path .isdir ( self .datatype_indexers_path ):
54
+ raise ConfigurationError ( "Directory does not exist: %s" % self .datatype_indexers_path )
55
+ if not self .display_applications_path :
56
+ self .display_applications_path = os .path .join ( root_dir , registration .get ( 'display_path' , 'display_applications' ) )
45
57
for elem in registration .findall ( 'datatype' ):
46
58
try :
47
59
extension = elem .get ( 'extension' , None )
@@ -55,11 +67,14 @@ def __init__( self, root_dir=None, config=None ):
55
67
fields = dtype .split ( ':' )
56
68
datatype_module = fields [0 ]
57
69
datatype_class_name = fields [1 ]
58
- fields = datatype_module .split ( '.' )
59
- module = __import__ ( fields .pop (0 ) )
60
- for mod in fields :
61
- module = getattr ( module , mod )
62
- datatype_class = getattr ( module , datatype_class_name )
70
+ if imported_module :
71
+ datatype_class = getattr ( imported_module , datatype_class_name )
72
+ else :
73
+ fields = datatype_module .split ( '.' )
74
+ module = __import__ ( fields .pop (0 ) )
75
+ for mod in fields :
76
+ module = getattr ( module , mod )
77
+ datatype_class = getattr ( module , datatype_class_name )
63
78
elif type_extension :
64
79
datatype_class = self .datatypes_by_extension [type_extension ].__class__
65
80
if make_subclass :
@@ -252,10 +267,8 @@ def append_to_sniff_order():
252
267
if not included :
253
268
self .sniff_order .append (datatype )
254
269
append_to_sniff_order ()
255
-
256
270
def get_available_tracks (self ):
257
271
return self .available_tracks
258
-
259
272
def get_mimetype_by_extension (self , ext , default = 'application/octet-stream' ):
260
273
"""Returns a mimetype based on an extension"""
261
274
try :
@@ -265,15 +278,13 @@ def get_mimetype_by_extension(self, ext, default = 'application/octet-stream' ):
265
278
mimetype = default
266
279
self .log .warning ('unknown mimetype in data factory %s' % ext )
267
280
return mimetype
268
-
269
281
def get_datatype_by_extension (self , ext ):
270
282
"""Returns a datatype based on an extension"""
271
283
try :
272
284
builder = self .datatypes_by_extension [ext ]
273
285
except KeyError :
274
286
builder = data .Text ()
275
287
return builder
276
-
277
288
def change_datatype (self , data , ext , set_meta = True ):
278
289
data .extension = ext
279
290
# call init_meta and copy metadata from itself. The datatype
@@ -287,15 +298,13 @@ def change_datatype(self, data, ext, set_meta = True ):
287
298
data .set_meta ( overwrite = False )
288
299
data .set_peek ()
289
300
return data
290
-
291
301
def old_change_datatype (self , data , ext ):
292
302
"""Creates and returns a new datatype based on an existing data and an extension"""
293
303
newdata = factory (ext )(id = data .id )
294
304
for key , value in data .__dict__ .items ():
295
305
setattr (newdata , key , value )
296
306
newdata .ext = ext
297
307
return newdata
298
-
299
308
def load_datatype_converters ( self , toolbox ):
300
309
"""Adds datatype converters from self.converters to the calling app's toolbox"""
301
310
for elem in self .converters :
@@ -312,7 +321,6 @@ def load_datatype_converters( self, toolbox ):
312
321
self .log .debug ( "Loaded converter: %s" , converter .id )
313
322
except :
314
323
self .log .exception ( "error reading converter from path: %s" % converter_path )
315
-
316
324
def load_external_metadata_tool ( self , toolbox ):
317
325
"""Adds a tool which is used to set external metadata"""
318
326
#we need to be able to add a job to the queue to set metadata. The queue will currently only accept jobs with an associated tool.
@@ -337,7 +345,6 @@ def load_external_metadata_tool( self, toolbox ):
337
345
toolbox .tools_by_id [ set_meta_tool .id ] = set_meta_tool
338
346
self .set_external_metadata_tool = set_meta_tool
339
347
self .log .debug ( "Loaded external metadata tool: %s" , self .set_external_metadata_tool .id )
340
-
341
348
def load_datatype_indexers ( self , toolbox ):
342
349
"""Adds indexers from self.indexers to the toolbox from app"""
343
350
for elem in self .indexers :
@@ -347,7 +354,6 @@ def load_datatype_indexers( self, toolbox ):
347
354
toolbox .tools_by_id [indexer .id ] = indexer
348
355
self .datatype_indexers [datatype ] = indexer
349
356
self .log .debug ( "Loaded indexer: %s" , indexer .id )
350
-
351
357
def get_converters_by_datatype (self , ext ):
352
358
"""Returns available converters by source type"""
353
359
converters = odict ()
@@ -360,7 +366,6 @@ def get_converters_by_datatype(self, ext):
360
366
if ext in self .datatype_converters .keys ():
361
367
converters .update (self .datatype_converters [ext ])
362
368
return converters
363
-
364
369
def get_indexers_by_datatype ( self , ext ):
365
370
"""Returns indexers based on datatype"""
366
371
class_chain = list ()
@@ -373,14 +378,12 @@ def get_indexers_by_datatype( self, ext ):
373
378
ext2type = lambda x : self .get_datatype_by_extension (x )
374
379
class_chain = sorted (class_chain , lambda x ,y : issubclass (ext2type (x ),ext2type (y )) and - 1 or 1 )
375
380
return [self .datatype_indexers [x ] for x in class_chain ]
376
-
377
381
def get_converter_by_target_type (self , source_ext , target_ext ):
378
382
"""Returns a converter based on source and target datatypes"""
379
383
converters = self .get_converters_by_datatype (source_ext )
380
384
if target_ext in converters .keys ():
381
385
return converters [target_ext ]
382
386
return None
383
-
384
387
def find_conversion_destination_for_dataset_by_extensions ( self , dataset , accepted_formats , converter_safe = True ):
385
388
"""Returns ( target_ext, existing converted dataset )"""
386
389
for convert_ext in self .get_converters_by_datatype ( dataset .ext ):
@@ -394,10 +397,8 @@ def find_conversion_destination_for_dataset_by_extensions( self, dataset, accept
394
397
ret_data = None
395
398
return ( convert_ext , ret_data )
396
399
return ( None , None )
397
-
398
400
def get_composite_extensions ( self ):
399
401
return [ ext for ( ext , d_type ) in self .datatypes_by_extension .iteritems () if d_type .composite_type is not None ]
400
-
401
402
def get_upload_metadata_params ( self , context , group , tool ):
402
403
"""Returns dict of case value:inputs for metadata conditional for upload tool"""
403
404
rval = {}
@@ -413,4 +414,3 @@ def get_upload_metadata_params( self, context, group, tool ):
413
414
if 'auto' not in rval and 'txt' in rval : #need to manually add 'auto' datatype
414
415
rval [ 'auto' ] = rval [ 'txt' ]
415
416
return rval
416
-
0 commit comments