Skip to content

Commit fe6bebd

Browse files
committed
Merge pull request #699 from satra/fix/reporting
fix: allow full path parsing in rename
2 parents 5b29641 + 8e32a43 commit fe6bebd

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

nipype/interfaces/utility.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,15 @@ def _list_outputs(self):
143143
class RenameInputSpec(DynamicTraitedSpec):
144144

145145
in_file = File(exists=True, mandatory=True, desc="file to rename")
146-
keep_ext = traits.Bool(desc="Keep in_file extension, replace non-extension component of name")
146+
keep_ext = traits.Bool(desc=("Keep in_file extension, replace "
147+
"non-extension component of name"))
147148
format_string = traits.String(mandatory=True,
148-
desc="Python formatting string for output template")
149-
parse_string = traits.String(desc="Python regexp parse string to define replacement inputs")
149+
desc=("Python formatting string for output "
150+
"template"))
151+
parse_string = traits.String(desc=("Python regexp parse string to define "
152+
"replacement inputs"))
153+
use_fullpath = traits.Bool(False, use_default=True,
154+
desc="Use full path as input to regex parser")
150155

151156

152157
class RenameOutputSpec(TraitedSpec):
@@ -210,22 +215,29 @@ def __init__(self, format_string=None, **inputs):
210215
def _rename(self):
211216
fmt_dict = dict()
212217
if isdefined(self.inputs.parse_string):
213-
m = re.search(self.inputs.parse_string, os.path.split(self.inputs.in_file)[1])
218+
if isdefined(self.inputs.use_fullpath) and self.inputs.use_fullpath:
219+
m = re.search(self.inputs.parse_string,
220+
self.inputs.in_file)
221+
else:
222+
m = re.search(self.inputs.parse_string,
223+
os.path.split(self.inputs.in_file)[1])
214224
if m:
215225
fmt_dict.update(m.groupdict())
216226
for field in self.fmt_fields:
217227
val = getattr(self.inputs, field)
218228
if isdefined(val):
219229
fmt_dict[field] = getattr(self.inputs, field)
220230
if self.inputs.keep_ext:
221-
fmt_string = "".join([self.inputs.format_string, split_filename(self.inputs.in_file)[2]])
231+
fmt_string = "".join([self.inputs.format_string,
232+
split_filename(self.inputs.in_file)[2]])
222233
else:
223234
fmt_string = self.inputs.format_string
224235
return fmt_string % fmt_dict
225236

226237
def _run_interface(self, runtime):
227238
runtime.returncode = 0
228-
_ = copyfile(self.inputs.in_file, os.path.join(os.getcwd(), self._rename()))
239+
_ = copyfile(self.inputs.in_file, os.path.join(os.getcwd(),
240+
self._rename()))
229241
return runtime
230242

231243
def _list_outputs(self):

0 commit comments

Comments
 (0)