parameter.py 22.7 KB
Newer Older
Jerome Mariette's avatar
Jerome Mariette committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#
# Copyright (C) 2012 INRA
# 
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

import types
Jerome Mariette's avatar
Jerome Mariette committed
19
import datetime
Jerome Mariette's avatar
Jerome Mariette committed
20
import logging
Jerome Mariette's avatar
Jerome Mariette committed
21
import argparse
Jerome Mariette's avatar
Jerome Mariette committed
22
23
import os
import tempfile
24
from argparse import _ensure_value
Jerome Mariette's avatar
Jerome Mariette committed
25
import urllib2
26
import copy as _copy
Jerome Mariette's avatar
Jerome Mariette committed
27
28
29
from urlparse import urlparse
from jflow.config_reader import JFlowConfigReader

Jerome Mariette's avatar
Jerome Mariette committed
30
31
# import custom types
from workflows.types import *
Jerome Mariette's avatar
Jerome Mariette committed
32

Jerome Mariette's avatar
Jerome Mariette committed
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# function in charge to download an url file
def download_urlfile(input):
    try:
        uri_object = urlparse(input)
        opener = urllib2.urlopen(input)
        block_size = 8000
        jflowconf = JFlowConfigReader()
        tmp_directory = os.path.join(jflowconf.get_tmp_directory(), os.path.basename(tempfile.NamedTemporaryFile().name))
        os.mkdir(tmp_directory) 
        file_path = os.path.join(tmp_directory, os.path.basename(uri_object.path))
        local_file = open(file_path, 'wb')
        if os.path.basename(uri_object.path) is not None and os.path.basename(uri_object.path) != "":
            metadata = opener.info()
            file_size = int(metadata.getheaders("Content-Length")[0])
            while True:
                buffer = opener.read(block_size)
                # End of download
                if not buffer: break
                # Parts of download
                local_file.write(buffer)
            local_file.close()
            logging.getLogger("types.urlfile").debug("URL file '{0}' successfully downloaded as: {1}".format(input, file_path))
        return [file_path, True]
    except:
        return [input, False]

# define all input type available
INPUTFILE_TYPES = ["inputfile", "localfile", "urlfile", "browsefile"]

def browsefile(file):
    # browsefile are not available from command line, considere it as a localfile
    # from the gui, this will not been tested this way
    return localfile(file)

def localfile(file):
    if os.path.isfile(file):
        return os.path.abspath(file)
    else:
        raise argparse.ArgumentTypeError("Local file '" + file + "' does not exists! Please provide a valid file path!")
    
def urlfile(file):
    uri_object = urlparse(file)
    try:
        opener = urllib2.urlopen(file)
    except:
        raise argparse.ArgumentTypeError("URL '" + file + "' is invalid!")
    file_name = os.path.basename(uri_object.path)
    if file_name is not None and file_name != "":
        metadata = opener.info()
        file_size = int(metadata.getheaders("Content-Length")[0])
        if file_size == 0:
            raise argparse.ArgumentTypeError("The URL file '" + file + "' is empty!")
        return file
    else:
        raise argparse.ArgumentTypeError("URL '" + file + "' does not contain any file name!")
    
def inputfile(file):
    # test the format
    uri_object = urlparse(file)
    # check the file
    if uri_object.scheme == '':
        return localfile(file)
    else:
        return urlfile(file)
    
Jerome Mariette's avatar
Jerome Mariette committed
98

Jerome Mariette's avatar
Jerome Mariette committed
99
class MultipleParameters(object):
100
    def __init__(self, types, required, choices, excludes, default, actions):
Jerome Mariette's avatar
Jerome Mariette committed
101
        self.types = types
102
        self.choices = choices
Jerome Mariette's avatar
Jerome Mariette committed
103
        self.excludes = excludes
104
        self.default = default
105
        self.actions = actions
Jerome Mariette's avatar
Jerome Mariette committed
106
        self.index = None
107
        self.required = required
Jerome Mariette's avatar
Jerome Mariette committed
108
        self.__name__ = "MultipleParameters"
109
        
Jerome Mariette's avatar
help ok    
Jerome Mariette committed
110
111
112
113
114
115
    def get_help(self):
        help = " ("
        for flag in self.types.keys():
            help += flag + "=<" + self.types[flag].__name__.upper() + ">, "
        return help[:-2] + ")"
        
116
    def __call__(self, arg):
Jerome Mariette's avatar
Jerome Mariette committed
117
118
119
        parts = arg.split("=")
        if not self.types.has_key(parts[0]):
            raise argparse.ArgumentTypeError(parts[0] + " is an invalid flag! Available ones are: "+", ".join(self.types.keys()))
120
121
122
        if self.choices[parts[0]] != None:
            if parts[1] not in self.choices[parts[0]]:
                raise argparse.ArgumentTypeError("argument " + parts[0] + ": invalid choice: '" + parts[1] + "' (choose from " + ", ".join(self.choices[parts[0]]) + "))")
123
124
125
126
127
128
129
130
131
132
        
        if self.types[parts[0]] == types.BooleanType:
            return (parts[0], not self.default[parts[0]], self.required, self.excludes)
        else:
            try:
                value = self.types[parts[0]](parts[1])
            except:
                raise argparse.ArgumentTypeError("invalid " + self.types[parts[0]].__name__ + " value: '" + parts[1] + "' for sub parameter '" + parts[0] + "'")
        
            self.index = parts[0]
133
            return (parts[0], value, self.required, self.excludes, self.actions)
Jerome Mariette's avatar
Jerome Mariette committed
134

135
136
class MiltipleAction(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
137
138
139
140
141
142
143
        # what is commun within required and excludes
        exclusif_required = {}
        for exclude_group in values[0][3]:
            exclusif_required[exclude_group] = False
            for param in values[0][3][exclude_group]:
                if param in values[0][2]:
                    exclusif_required[exclude_group] = True
Jerome Mariette's avatar
Jerome Mariette committed
144
145
        given_params = []
        # first check for required parameters
146
147
        try:
            required = _copy.copy(values[0][2])
148
149
150
151
152
153
            # delete required that are exclusive
            for group in exclusif_required:
                if exclusif_required[group]:
                    for val in values[0][3][group]:
                        if val in required:
                            del required[required.index(val)]
154
            for val in values:
Jerome Mariette's avatar
Jerome Mariette committed
155
                given_params.append(val[0])
156
157
158
159
160
                if val[0] in required:
                    del required[required.index(val[0])]
        except: pass
        if len(required) == 1: parser.error(", ".join(required) + " is a required parameter!")
        elif len(required) > 1: parser.error(", ".join(required) + " are required parameters!")
Jerome Mariette's avatar
Jerome Mariette committed
161
162
163
164
165
166
167
168
        # then for exclude ones    
        for exclude_group in values[0][3]:
            found = None
            for param in values[0][3][exclude_group]:
                if param in given_params and found != None:
                    parser.error("argument '" + found + "': not allowed with argument '" + param + "'")
                    break
                elif param in given_params: found = param
169
170
171
172
173
174
175
176
177
        
        # check for required exclusive if one of them is in
        if len(exclusif_required.keys()) > 0:
            for group in exclusif_required:
                if exclusif_required[group]:
                    rfound = False
                    for param in values[0][3][group]:
                        if param in given_params: rfound = True
            if not rfound: parser.error("one of the arguments: " + ", ".join(values[0][3][group]) + " is required")
178
        
Jerome Mariette's avatar
Jerome Mariette committed
179
        # if ok add the value
180
181
182
183
184
185
186
187
188
189
190
        final_hash, final_values = {}, []
        for value in values:
            if values[0][4][value[0]] == "append" and final_hash.has_key(value[0]):
                final_hash[value[0]].append(value[1])
            elif values[0][4][value[0]] == "append":
                final_hash[value[0]]= [value[1]]
            else:
                final_hash[value[0]]= value[1]
        for param in final_hash:
            final_values.append((param, final_hash[param]))
        setattr(namespace, self.dest, final_values)
191
192
193

class MiltipleAppendAction(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
194
195
196
197
198
199
200
        # what is commun within required and excludes
        exclusif_required = {}
        for exclude_group in values[0][3]:
            exclusif_required[exclude_group] = False
            for param in values[0][3][exclude_group]:
                if param in values[0][2]:
                    exclusif_required[exclude_group] = True
Jerome Mariette's avatar
Jerome Mariette committed
201
202
        given_params = []
        # first check for required parameters
203
204
        try:
            required = _copy.copy(values[0][2])
205
206
207
208
209
210
            # delete required that are exclusive
            for group in exclusif_required:
                if exclusif_required[group]:
                    for val in values[0][3][group]:
                        if val in required:
                            del required[required.index(val)]
211
            for val in values:
Jerome Mariette's avatar
Jerome Mariette committed
212
                given_params.append(val[0])
213
214
215
216
217
                if val[0] in required:
                    del required[required.index(val[0])]
        except: pass
        if len(required) == 1: parser.error(", ".join(required) + " is a required parameter!")
        elif len(required) > 1: parser.error(", ".join(required) + " are required parameters!")
Jerome Mariette's avatar
Jerome Mariette committed
218
219
220
221
222
223
224
225
        # then for exclude ones    
        for exclude_group in values[0][3]:
            found = None
            for param in values[0][3][exclude_group]:
                if param in given_params and found != None:
                    parser.error("argument '" + found + "': not allowed with argument '" + param + "'")
                    break
                elif param in given_params: found = param
226
227
228
229
230
231
232
233
234
        
        # check for required exclusive if one of them is in
        if len(exclusif_required.keys()) > 0:
            for group in exclusif_required:
                if exclusif_required[group]:
                    rfound = False
                    for param in values[0][3][group]:
                        if param in given_params: rfound = True
            if not rfound: parser.error("one of the arguments: " + ", ".join(values[0][3][group]) + " is required")
Jerome Mariette's avatar
Jerome Mariette committed
235
        # if ok add the value
236
        items = _copy.copy(_ensure_value(namespace, self.dest, []))
237
238
239
240
241
242
243
244
245
246
247
        final_hash, final_values = {}, []
        for value in values:
            if values[0][4][value[0]] == "append" and final_hash.has_key(value[0]):
                final_hash[value[0]].append(value[1])
            elif values[0][4][value[0]] == "append":
                final_hash[value[0]]= [value[1]]
            else:
                final_hash[value[0]]= value[1]
        for param in final_hash:
            final_values.append((param, final_hash[param]))
        items.append(final_values)
248
        setattr(namespace, self.dest, items)        
249
250
251


class AbstractParameter(object):
Jerome Mariette's avatar
Jerome Mariette committed
252
    
253
254
    def __init__(self, name, help, default=None, type=types.StringType, choices=None, required=False,
                 flag=None, action="store", sub_parameters=None, group="default", display_name=None):
Jerome Mariette's avatar
Jerome Mariette committed
255

Jerome Mariette's avatar
Jerome Mariette committed
256
257
        self.name = name
        self.help = help
258
        self.action = action
Jerome Mariette's avatar
Jerome Mariette committed
259
        self.nargs = None
260
261
262
        if sub_parameters:
            self.sub_parameters = sub_parameters
        else: self.sub_parameters = []
Jerome Mariette's avatar
Jerome Mariette committed
263
        self.group = group
264
265
266
267
268
        if flag == None:
            self.flag = "--"+name.replace("_", "-")
        else: self.flag = flag
        if display_name == None: 
            self.display_name = name.replace("_", " ").title()
Jerome Mariette's avatar
Jerome Mariette committed
269
        else: self.display_name = display_name
Jerome Mariette's avatar
help ok    
Jerome Mariette committed
270
        self.required = required
271
        self.choices = choices
Jerome Mariette's avatar
Jerome Mariette committed
272
        
Jerome Mariette's avatar
Jerome Mariette committed
273
274
        if type == "date":
            self.type = date
Jerome Mariette's avatar
Jerome Mariette committed
275
        elif type == "multiple":
Jerome Mariette's avatar
help ok    
Jerome Mariette committed
276
            self.type = "multiple"
Jerome Mariette's avatar
Jerome Mariette committed
277
278
        elif isinstance(type, types.FunctionType):
            self.type = type
Jerome Mariette's avatar
Jerome Mariette committed
279
280
281
        else:
            try: self.type = eval(type)
            except: self.type = types.StringType
Jerome Mariette's avatar
Jerome Mariette committed
282
                        
Jerome Mariette's avatar
Jerome Mariette committed
283
        self.default = default
Jerome Mariette's avatar
help ok    
Jerome Mariette committed
284
        if self.type == "date" and not self.default:
Jerome Mariette's avatar
Jerome Mariette committed
285
286
            today = datetime.date.today()
            self.default = today.strftime('%d/%m/%Y')
287
        elif self.type == types.BooleanType :
Jerome Mariette's avatar
Jerome Mariette committed
288
289
            if self.default: self.default = str(self.default).lower() in ("true",  "t", "1")
            else: self.default = True
Jerome Mariette's avatar
Jerome Mariette committed
290
291
        elif self.action == "append":
            self.default = []
292
    
293
    def export_to_argparse(self):
294
295
296
297
        if self.type == types.BooleanType and str(self.default).lower() in ("false",  "f", "0"):
            return {"help": self.help, "required": self.required, "dest": self.name, 
                    "default": False, "action": "store_true"}
        elif self.type == types.BooleanType:
298
            return {"help": self.help, "required": self.required, "dest": self.name, 
299
                    "default": True, "action": "store_false"}
Jerome Mariette's avatar
Jerome Mariette committed
300
301
302
        elif self.nargs > 1:
            return {"type": self.type, "help": self.help, "required": self.required,
                    "dest": self.name, "default": self.default,
Jerome Mariette's avatar
Jerome Mariette committed
303
                    "action": self.action, "choices": self.choices, "nargs": "+"}
304
305
        else:
            return {"type": self.type, "help": self.help, "required": self.required,
Jerome Mariette's avatar
Jerome Mariette committed
306
                    "dest": self.name, "default": self.default,
307
308
                    "action": self.action, "choices": self.choices}
    
Jerome Mariette's avatar
Jerome Mariette committed
309
310
311
    def get_type(self):
        return self.type.__name__
    
Jerome Mariette's avatar
Jerome Mariette committed
312
313
314
315
316
317
318
319
320
321
322
323
324
325
    
class AbstractFile(object):
    def __init__(self, file_format="any"):
        self.file_format = file_format
        self.parent_component_nameid = None


class MultiParameter(dict, AbstractParameter):
    
    def __init__(self, name, help, required=False, flag=None, group="default", display_name=None):
        AbstractParameter.__init__(self, name, help, required=required, type="multiple", flag=flag, group=group, 
                                   display_name=display_name)
        return dict.__init__(self, {})

Jerome Mariette's avatar
help ok    
Jerome Mariette committed
326
327
328
    def add_sub_parameter(self, param):
        param_flag = param.flag[2:]
        if self.type == "multiple":
Jerome Mariette's avatar
Jerome Mariette committed
329
330
331
            if param.required: req = [param_flag] 
            else: req = []
            self.type = MultipleParameters({param_flag: param.type}, req, 
Jerome Mariette's avatar
help ok    
Jerome Mariette committed
332
333
334
335
336
337
338
339
                                           {param_flag: param.choices}, {}, {param_flag: param.default},
                                           {param_flag: param.action})
            if self.action == "append":
                self.action = MiltipleAppendAction
            else:
                self.action = MiltipleAction
            self.global_help = self.help
            self.help = self.global_help + " (" + param_flag + "=<" + param.type.__name__.upper() + ">)"
Jerome Mariette's avatar
Jerome Mariette committed
340
            self.default = {}
Jerome Mariette's avatar
Jerome Mariette committed
341
            self.nargs = "+"
Jerome Mariette's avatar
help ok    
Jerome Mariette committed
342
343
344
345
346
        elif self.type.__class__ == MultipleParameters:
            self.type.types[param_flag] = param.type
            self.type.choices[param_flag] = param.choices
            self.type.default[param_flag] = param.default
            self.type.actions[param_flag] = param.action
Jerome Mariette's avatar
Jerome Mariette committed
347
348
            if param.required:
                self.type.required.append(param_flag)
Jerome Mariette's avatar
help ok    
Jerome Mariette committed
349
            self.help = self.global_help + self.type.get_help()
Jerome Mariette's avatar
Jerome Mariette committed
350
        param.flag = param_flag
Jerome Mariette's avatar
help ok    
Jerome Mariette committed
351
        self.sub_parameters.append(param)
Jerome Mariette's avatar
Jerome Mariette committed
352
        
353
354
355
356

class MultiParameterList(list, AbstractParameter):
    
    def __init__(self, name, help, required=False, flag=None, group="default", display_name=None):
Jerome Mariette's avatar
help ok    
Jerome Mariette committed
357
358
        AbstractParameter.__init__(self, name, help, required=required, type="multiple", flag=flag, 
                                   action="append", group=group, display_name=display_name)
359
        return list.__init__(self, [])
Jerome Mariette's avatar
Jerome Mariette committed
360

Jerome Mariette's avatar
Jerome Mariette committed
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
    def add_sub_parameter(self, param):
        param_flag = param.flag[2:]
        if self.type == "multiple":
            if param.required: req = [param_flag] 
            else: req = []
            self.type = MultipleParameters({param_flag: param.type}, req, 
                                           {param_flag: param.choices}, {}, {param_flag: param.default},
                                           {param_flag: param.action})
            if self.action == "append":
                self.action = MiltipleAppendAction
            else:
                self.action = MiltipleAction
            self.global_help = self.help
            self.help = self.global_help + " (" + param_flag + "=<" + param.type.__name__.upper() + ">)"
            self.default = []
            self.nargs = "+"
        elif self.type.__class__ == MultipleParameters:
            self.type.types[param_flag] = param.type
            self.type.choices[param_flag] = param.choices
            self.type.default[param_flag] = param.default
            self.type.actions[param_flag] = param.action
            if param.required:
                self.type.required.append(param_flag)
            self.help = self.global_help + self.type.get_help()
        param.flag = param_flag
        self.sub_parameters.append(param)

388
389
390
391
392
393
394
395
396
397
398
399
400
401
402

class Parameter(str, AbstractParameter):
    
    def __new__(self, name, help, default="", type=types.StringType, choices=None, required=False,
                flag=None, sub_parameters=None, group="default", display_name=None):
        return str.__new__(self, default)
    
    def __init__(self, name, help, default="", type=types.StringType, choices=None, required=False,
                 flag=None, sub_parameters=None, group="default", display_name=None):
        AbstractParameter.__init__(self, name, help, flag=flag, type=type, choices=choices, required=required, 
                                   action="store", sub_parameters=sub_parameters, group=group, display_name=display_name)
        

class InputFile(Parameter, AbstractFile):
    
Jerome Mariette's avatar
Jerome Mariette committed
403
    def __new__(self, name, help, file_format="any", default="", type="localfile", choices=None, 
404
                required=False, flag=None, group="default", display_name=None):
Jerome Mariette's avatar
Jerome Mariette committed
405
406
407
408
409
410
411
412
413
        
        if hasattr(type, '__call__'):
            type2test = type.__name__
        else: type2test = type
        
        if type2test not in INPUTFILE_TYPES:
            raise ValueError("InputFile.__new__: wrong type provided: '"+type2test+"', this should be choosen between '" 
                             + "', '".join(INPUTFILE_TYPES)+"'")
        
414
415
        return str.__new__(self, default)
    
Jerome Mariette's avatar
Jerome Mariette committed
416
    def __init__(self, name, help, file_format="any", default="", type="localfile", choices=None, 
417
418
419
420
                required=False, flag=None, group="default", display_name=None):
        AbstractFile.__init__(self, file_format)
        Parameter.__init__(self, name, help, flag=flag, type=type, choices=choices, 
                           required=required, group=group, display_name=display_name)
Jerome Mariette's avatar
Jerome Mariette committed
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
    """
    def _prepare_input_files(self):
        # handle url inputs
        if self.type.__name__ == "inputfile" or self.type.__name__ == "urlfile":
            new_args[param], is_uri = self._download_urlfile(args[param])
        
        kparams = {}
        for param in parameters:
            kparams[param.name] = param
        new_args = args
        for param in args.keys():
            is_uri, is_local = False, False
            # handle url inputs
            if kparams[param].type.__name__ == "inputfile" or kparams[param].type.__name__ == "urlfile":
                if args[param].__class__.__name__ == "list":
                    for i, val in enumerate(args[param]):
                        new_args[param][i], is_uri = self._download_urlfile(args[param][i])
                else:
                    new_args[param], is_uri = self._download_urlfile(args[param])
            # handle upload inputs
            try: is_local = os.path.isfile(args[param])
            except: is_local = False
            if not is_uri and not is_local and (kparams[param].type.__name__ == "inputfile" or kparams[param].type.__name__ == "browsefile"):
                if args[param].__class__.__name__ == "list":
                    for i, val in enumerate(args[param]):
                        if args[param][i]:
                            new_args[param][i] = os.path.join(self.jflow_config_reader.get_tmp_directory(), (args[param][i]))
                else:
                    if args[param]:
                        new_args[param] = os.path.join(self.jflow_config_reader.get_tmp_directory(), (args[param]))
        return new_args
    """
453
454
455

class OutputFile(Parameter, AbstractFile):
    
Jerome Mariette's avatar
Jerome Mariette committed
456
    def __new__(self, name, help, file_format="any", default="", choices=None, 
457
458
459
                required=False, flag=None, group="default", display_name=None):
        return str.__new__(self, default)
    
Jerome Mariette's avatar
Jerome Mariette committed
460
    def __init__(self, name, help, file_format="any", default="", choices=None, 
461
462
                required=False, flag=None, group="default", display_name=None):
        AbstractFile.__init__(self, file_format)
Jerome Mariette's avatar
Jerome Mariette committed
463
        Parameter.__init__(self, name, help, flag=flag, type="localfile", choices=choices, 
464
465
466
467
468
                           required=required, group=group, display_name=display_name)

        
class ParameterList(list, AbstractParameter):
    
Jerome Mariette's avatar
Jerome Mariette committed
469
    def __init__(self, name, help, default=None, type=types.StringType, choices=None, required=False,
470
                 flag=None, sub_parameters=None, group="default", display_name=None):
Jerome Mariette's avatar
Jerome Mariette committed
471
        if default == None: default = []
472
473
474
475
476
477
478
479
480
481
        AbstractParameter.__init__(self, name, help, flag=flag, type=type, choices=choices, required=required, 
                                   action="append", sub_parameters=sub_parameters, group=group, display_name=display_name)
        if default.__class__.__name__ == "str":
            return list.__init__(self, [default])
        elif default.__class__.__name__ == "list":
            return list.__init__(self, default)
        

class InputFileList(ParameterList, AbstractFile):
    
Jerome Mariette's avatar
Jerome Mariette committed
482
    def __init__(self, name, help, file_format="any", default=None, type="localfile", choices=None, 
483
                 required=False, flag=None, group="default", display_name=None):
Jerome Mariette's avatar
Jerome Mariette committed
484
485
486
487
488
489
490
491
492
493
494
        
        if default == None: default = []
        
        if hasattr(type, '__call__'):
            type2test = type.__name__
        else: type2test = type
        
        if type2test not in INPUTFILE_TYPES:
            raise ValueError("InputFile.__new__: wrong type provided: '"+type2test+"', this should be choosen between '" 
                             + "', '".join(INPUTFILE_TYPES)+"'")
        
495
496
497
498
499
500
501
502
503
504
505
        AbstractFile.__init__(self, file_format)
        ParameterList.__init__(self, name, help, flag=flag, type=type, choices=choices, 
                               required=required, group=group, display_name=display_name)
        if default.__class__.__name__ == "str":
            return list.__init__(self, [default])
        elif default.__class__.__name__ == "list":
            return list.__init__(self, default)


class OutputFileList(ParameterList, AbstractFile):
    
Jerome Mariette's avatar
Jerome Mariette committed
506
507
508
    def __init__(self, name, help, file_format="any", default=None, choices=None, 
                 required=False, flag=None, group="default", display_name=None):
        if default == None: default = []
509
        AbstractFile.__init__(self, file_format)
Jerome Mariette's avatar
Jerome Mariette committed
510
        ParameterList.__init__(self, name, help, flag=flag, type="localfile", choices=choices, 
511
512
513
514
515
                               required=required, group=group, display_name=display_name)
        if default.__class__.__name__ == "str":
            return list.__init__(self, [default])
        elif default.__class__.__name__ == "list":
            return list.__init__(self, default)