|
11 | 11 | from distutils import spawn
|
12 | 12 |
|
13 | 13 | from ... import logging, LooseVersion
|
14 |
| -from ...utils.filemanip import split_filename |
| 14 | +from ...utils.filemanip import split_filename, fname_presuffix |
15 | 15 | from ..base import (CommandLine, traits, CommandLineInputSpec, isdefined, File,
|
16 | 16 | TraitedSpec, PackageInfo)
|
17 | 17 | from ...external.due import BibTeX
|
@@ -237,6 +237,55 @@ def _list_outputs(self):
|
237 | 237 | outputs[name] = outputs[name] + "+orig.BRIK"
|
238 | 238 | return outputs
|
239 | 239 |
|
| 240 | + def _gen_fname(self, |
| 241 | + basename, |
| 242 | + cwd=None, |
| 243 | + suffix=None, |
| 244 | + change_ext=True, |
| 245 | + ext=None): |
| 246 | + """ |
| 247 | + Generate a filename based on the given parameters. |
| 248 | +
|
| 249 | + The filename will take the form: cwd/basename<suffix><ext>. |
| 250 | + If change_ext is True, it will use the extentions specified in |
| 251 | + <instance>intputs.output_type. |
| 252 | +
|
| 253 | + Parameters |
| 254 | + ---------- |
| 255 | + basename : str |
| 256 | + Filename to base the new filename on. |
| 257 | + cwd : str |
| 258 | + Path to prefix to the new filename. (default is os.getcwd()) |
| 259 | + suffix : str |
| 260 | + Suffix to add to the `basename`. (defaults is '' ) |
| 261 | + change_ext : bool |
| 262 | + Flag to change the filename extension to the FSL output type. |
| 263 | + (default True) |
| 264 | +
|
| 265 | + Returns |
| 266 | + ------- |
| 267 | + fname : str |
| 268 | + New filename based on given parameters. |
| 269 | +
|
| 270 | + """ |
| 271 | + if not basename: |
| 272 | + msg = 'Unable to generate filename for command %s. ' % self.cmd |
| 273 | + msg += 'basename is not set!' |
| 274 | + raise ValueError(msg) |
| 275 | + |
| 276 | + if cwd is None: |
| 277 | + cwd = os.getcwd() |
| 278 | + if ext is None: |
| 279 | + ext = Info.output_type_to_ext(self.inputs.outputtype) |
| 280 | + if change_ext: |
| 281 | + suffix = ''.join((suffix, ext)) if suffix else ext |
| 282 | + |
| 283 | + if suffix is None: |
| 284 | + suffix = '' |
| 285 | + fname = fname_presuffix( |
| 286 | + basename, suffix=suffix, use_ext=False, newpath=cwd) |
| 287 | + return fname |
| 288 | + |
240 | 289 |
|
241 | 290 | def no_afni():
|
242 | 291 | """Check whether AFNI is not available."""
|
|
0 commit comments