10
10
from sys import platform
11
11
12
12
from ... import logging
13
- from ...utils .filemanip import split_filename
13
+ from ...utils .filemanip import split_filename , fname_presuffix
14
+
14
15
from ..base import (
15
16
CommandLine , traits , CommandLineInputSpec , isdefined , File , TraitedSpec )
16
17
from ...external .due import BibTeX
@@ -70,7 +71,7 @@ def version():
70
71
return tuple (v )
71
72
72
73
@classmethod
73
- def outputtype_to_ext (cls , outputtype ):
74
+ def output_type_to_ext (cls , outputtype ):
74
75
"""Get the file extension for the given output type.
75
76
76
77
Parameters
@@ -217,7 +218,7 @@ def set_default_output_type(cls, outputtype):
217
218
218
219
def _overload_extension (self , value , name = None ):
219
220
path , base , _ = split_filename (value )
220
- return os .path .join (path , base + Info .outputtype_to_ext (self .inputs .outputtype ))
221
+ return os .path .join (path , base + Info .output_type_to_ext (self .inputs .outputtype ))
221
222
222
223
def _list_outputs (self ):
223
224
outputs = super (AFNICommand , self )._list_outputs ()
@@ -231,6 +232,51 @@ def _list_outputs(self):
231
232
outputs [name ] = outputs [name ] + "+orig.BRIK"
232
233
return outputs
233
234
235
+ def _gen_fname (self , basename , cwd = None , suffix = None , change_ext = True ,
236
+ ext = None ):
237
+ """Generate a filename based on the given parameters.
238
+
239
+ The filename will take the form: cwd/basename<suffix><ext>.
240
+ If change_ext is True, it will use the extentions specified in
241
+ <instance>intputs.output_type.
242
+
243
+ Parameters
244
+ ----------
245
+ basename : str
246
+ Filename to base the new filename on.
247
+ cwd : str
248
+ Path to prefix to the new filename. (default is os.getcwd())
249
+ suffix : str
250
+ Suffix to add to the `basename`. (defaults is '' )
251
+ change_ext : bool
252
+ Flag to change the filename extension to the FSL output type.
253
+ (default True)
254
+
255
+ Returns
256
+ -------
257
+ fname : str
258
+ New filename based on given parameters.
259
+
260
+ """
261
+
262
+ if basename == '' :
263
+ msg = 'Unable to generate filename for command %s. ' % self .cmd
264
+ msg += 'basename is not set!'
265
+ raise ValueError (msg )
266
+ if cwd is None :
267
+ cwd = os .getcwd ()
268
+ if ext is None :
269
+ ext = Info .output_type_to_ext (self .inputs .outputtype )
270
+ if change_ext :
271
+ if suffix :
272
+ suffix = '' .join ((suffix , ext ))
273
+ else :
274
+ suffix = ext
275
+ if suffix is None :
276
+ suffix = ''
277
+ fname = fname_presuffix (basename , suffix = suffix ,
278
+ use_ext = False , newpath = cwd )
279
+ return fname
234
280
235
281
def no_afni ():
236
282
""" Checks if AFNI is available """
0 commit comments