8
8
import os
9
9
import argparse
10
10
import sys
11
+ import logging
11
12
12
13
# External libraries
13
14
import ruamel .yaml
14
15
import six
15
16
from .version import __version__
16
17
18
+ logging .basicConfig (level = logging .INFO )
19
+ LOGGER = logging .getLogger (__name__ )
20
+
17
21
########### Constant(s) ###########
18
22
19
23
CWL_SHEBANG = "#!/usr/bin/env cwl-runner"
20
- DEF_CWL_VERSION = 'v1.0'
24
+ CWL_VERSIONS = ['draft-2' , 'draft-3.dev1' , 'draft-3.dev2' , 'draft-3.dev3' ,
25
+ 'draft-3.dev4' , 'draft-3.dev5' , 'draft-3' , 'draft-4.dev1' ,
26
+ 'draft-4.dev2' , 'draft-4.dev3' , 'v1.0.dev4' , 'v1.0' , None ]
21
27
CWL_TYPE = ['null' , 'boolean' , 'int' , 'long' , 'float' , 'double' , 'string' , 'File' ,
22
28
'Directory' , None ]
23
29
@@ -31,7 +37,7 @@ class CommandLineTool(object):
31
37
'''
32
38
33
39
def __init__ (self , tool_id = None , base_command = None , label = None , doc = None ,\
34
- cwl_version = DEF_CWL_VERSION , stdin = None , stderr = None , stdout = None ):
40
+ cwl_version = None , stdin = None , stderr = None , stdout = None ):
35
41
'''
36
42
:param tool_id: unique identifier for this tool.
37
43
:type tool_id: STRING
@@ -56,35 +62,32 @@ def __init__(self, tool_id=None, base_command=None, label=None, doc=None,\
56
62
and requirements (:class:`cwlgen.Requirement` objects)
57
63
are stored in lists which are initialized empty.
58
64
'''
59
- self .tool_id = tool_id
60
- self .base_command = base_command
65
+ self .id = tool_id
66
+ self .baseCommand = base_command
61
67
self .label = label
62
68
self .doc = doc
63
- self .cwl_version = cwl_version
69
+ if not cwl_version in CWL_VERSIONS :
70
+ LOGGER .warning ("CWL version is not recognized as a valid version." )
71
+ cwl_version = None
72
+ self .cwlVersion = cwl_version
64
73
self .stdin = stdin
65
74
self .stderr = stderr
66
75
self .stdout = stdout
67
- self .inputs = [] # List of [CommandInputParameter] objects
68
- self .outputs = [] # List of [CommandOutputParameter] objects
69
- self .arguments = [] # List of [CommandLineBinding] objects
70
- self .requirements = [] # List of Several object inhereting from [Requirement]
76
+ self .inputs = [] # List of [CommandInputParameter] objects
77
+ self .outputs = [] # List of [CommandOutputParameter] objects
78
+ self .arguments = [] # List of [CommandLineBinding] objects
79
+ self .requirements = [] # List of Several object inhereting from [Requirement]
71
80
self .hints = []
72
- self .success_codes = []
73
- self .temporary_fail_codes = []
74
- self .permanent_fail_codes = []
81
+ self .successCodes = []
82
+ self .temporaryFailCodes = []
83
+ self .permanentFailCodes = []
75
84
76
85
def export (self , outfile = None ):
77
86
'''
78
87
Export the tool in CWL either on STDOUT or in outfile
79
88
'''
80
- cwl_tool = {}
81
- cwl_tool ['cwlVersion' ] = self .cwl_version
82
- cwl_tool ['id' ] = self .tool_id
83
- cwl_tool ['label' ] = self .label
84
- cwl_tool ['baseCommand' ] = self .base_command
89
+ cwl_tool = {k :v for k ,v in vars (self ).items () if v is not None and v != []}
85
90
cwl_tool ['class' ] = 'CommandLineTool'
86
- if self .doc is not None :
87
- cwl_tool ['doc' ] = self .doc
88
91
# Add Inputs
89
92
if self .inputs :
90
93
cwl_tool ['inputs' ] = {}
@@ -127,11 +130,11 @@ def __init__(self, param_id, label=None, secondary_files=None, param_format=None
127
130
param_type: type of data assigned to the parameter [STRING] corresponding to CWLType
128
131
'''
129
132
if not param_type in CWL_TYPE :
130
- print ("The type is incorrect for the parameter" )
131
- return 1
133
+ LOGGER . warning ("The type is incorrect for the parameter" )
134
+ param_type = None
132
135
self .id = param_id
133
136
self .label = label
134
- self .secondary_files = secondary_files
137
+ self .secondaryFiles = secondary_files
135
138
self .format = param_format
136
139
self .streamable = streamable
137
140
self .doc = doc
@@ -144,20 +147,14 @@ def get_dict(self):
144
147
:return: dictionnary of the object
145
148
:rtype: DICT
146
149
'''
147
- dict_param = {}
148
- if self .type :
149
- dict_param ['type' ] = self .type
150
- if self .doc :
151
- dict_param ['doc' ] = self .doc
152
- if self .label :
153
- dict_param ['label' ] = self .label
154
- if self .type == 'File' :
155
- if self .format :
156
- dict_param ['format' ] = self .format
157
- if self .secondary_files :
158
- dict_param ['secondaryFiles' ] = self .secondary_files
159
- if self .streamable :
160
- dict_param ['streamable' ] = self .streamable
150
+ dict_param = {k :v for k ,v in vars (self ).items () if v is not None and v is not False }
151
+ if dict_param ['type' ] != 'File' :
152
+ # Remove what is only for File
153
+ for key in ['format' , 'secondaryFiles' , 'streamable' ]:
154
+ try :
155
+ del (dict_param [key ])
156
+ except KeyError :
157
+ pass
161
158
return dict_param
162
159
163
160
@@ -193,7 +190,7 @@ def __init__(self, param_id, label=None, secondary_files=None, param_format=None
193
190
Parameter .__init__ (self , param_id = param_id , label = label , \
194
191
secondary_files = secondary_files , param_format = param_format ,\
195
192
streamable = streamable , doc = doc , param_type = param_type )
196
- self .input_binding = input_binding
193
+ self .inputBinding = input_binding
197
194
self .default = default
198
195
199
196
def get_dict (self ):
@@ -204,10 +201,8 @@ def get_dict(self):
204
201
:rtype: DICT
205
202
'''
206
203
dict_in = Parameter .get_dict (self )
207
- if self .default :
208
- dict_in ['default' ] = self .default
209
- if self .input_binding :
210
- dict_in ['inputBinding' ] = self .input_binding .get_dict ()
204
+ if self .inputBinding :
205
+ dict_in ['inputBinding' ] = self .inputBinding .get_dict ()
211
206
return dict_in
212
207
213
208
@@ -240,7 +235,7 @@ def __init__(self, param_id, label=None, secondary_files=None, param_format=None
240
235
'''
241
236
Parameter .__init__ (self , param_id , label , secondary_files , param_format , streamable ,\
242
237
doc , param_type )
243
- self .output_binding = output_binding
238
+ self .outputBinding = output_binding
244
239
245
240
def get_dict (self ):
246
241
'''
@@ -250,8 +245,8 @@ def get_dict(self):
250
245
:rtype: DICT
251
246
'''
252
247
dict_out = Parameter .get_dict (self )
253
- if self .output_binding :
254
- dict_out ['outputBinding' ] = self .output_binding .get_dict ()
248
+ if self .outputBinding :
249
+ dict_out ['outputBinding' ] = self .outputBinding .get_dict ()
255
250
return dict_out
256
251
257
252
@@ -278,13 +273,13 @@ def __init__(self, load_contents=False, position=None, prefix=None, separate=Fal
278
273
:param shell_quote:
279
274
:type shell_quote: BOOLEAN
280
275
'''
281
- self .load_contents = load_contents
276
+ self .loadContents = load_contents
282
277
self .position = position
283
278
self .prefix = prefix
284
279
self .separate = separate
285
- self .item_separator = item_separator
286
- self .value_from = value_from
287
- self .shell_quote = shell_quote
280
+ self .itemSeparator = item_separator
281
+ self .valueFrom = value_from
282
+ self .shellQuote = shell_quote
288
283
289
284
def get_dict (self ):
290
285
'''
@@ -293,22 +288,7 @@ def get_dict(self):
293
288
:return: dictionnary of the object
294
289
:rtype: DICT
295
290
'''
296
- dict_binding = {}
297
- if self .load_contents :
298
- # Does not take care if type: File for the moment
299
- dict_binding ['loadContents' ] = self .load_contents
300
- if self .position :
301
- dict_binding ['position' ] = self .position
302
- if self .prefix :
303
- dict_binding ['prefix' ] = self .prefix
304
- if self .separate :
305
- dict_binding ['separate' ] = self .separate
306
- if self .item_separator :
307
- dict_binding ['itemSeparator' ] = self .item_separator
308
- if self .value_from :
309
- dict_binding ['valueFrom' ] = self .value_from
310
- if self .shell_quote :
311
- dict_binding ['shellQuote' ] = self .shell_quote
291
+ dict_binding = {k :v for k ,v in vars (self ).items () if v is not None and v is not False }
312
292
return dict_binding
313
293
314
294
@@ -328,8 +308,8 @@ def __init__(self, glob=False, load_contents=False, output_eval=None):
328
308
:type output_eval: STRING
329
309
'''
330
310
self .glob = glob
331
- self .load_contents = load_contents
332
- self .output_eval = output_eval
311
+ self .loadContents = load_contents
312
+ self .outputEval = output_eval
333
313
334
314
def get_dict (self ):
335
315
'''
@@ -338,13 +318,7 @@ def get_dict(self):
338
318
:return: dictionnary of the object
339
319
:rtype: DICT
340
320
'''
341
- dict_binding = {}
342
- if self .glob :
343
- dict_binding ['glob' ] = self .glob
344
- if self .load_contents :
345
- dict_binding ['loadContents' ] = self .load_contents
346
- if self .output_eval :
347
- dict_binding ['outputEval' ] = self .output_eval
321
+ dict_binding = {k :v for k ,v in vars (self ).items () if v is not None and v is not False }
348
322
return dict_binding
349
323
350
324
@@ -372,7 +346,7 @@ def __init__(self, expression_lib=None):
372
346
:type expression_lib: STRING
373
347
'''
374
348
Requirement .__init__ (self , 'InlineJavascriptRequirement' )
375
- self .expression_lib = expression_lib
349
+ self .expressionLib = expression_lib
376
350
377
351
378
352
class DockerRequirement (Requirement ):
@@ -398,9 +372,9 @@ def __init__(self, docker_pull=None, docker_load=None, docker_file=None,\
398
372
:type docker_output_dir: STRING
399
373
'''
400
374
Requirement .__init__ (self , 'DockerRequirement' )
401
- self .docker_pull = docker_pull
402
- self .docker_load = docker_load
403
- self .docker_file = docker_file
404
- self .docker_import = docker_import
405
- self .docker_image_id = docker_image_id
406
- self .docker_output_dir = docker_output_dir
375
+ self .dockerPull = docker_pull
376
+ self .dockerLoad = docker_load
377
+ self .dockerFile = docker_file
378
+ self .dockerImport = docker_import
379
+ self .dockerImageId = docker_image_id
380
+ self .dockerOutputDir = docker_output_dir
0 commit comments