@@ -143,10 +143,15 @@ def _list_outputs(self):
143
143
class RenameInputSpec (DynamicTraitedSpec ):
144
144
145
145
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" ))
147
148
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" )
150
155
151
156
152
157
class RenameOutputSpec (TraitedSpec ):
@@ -210,22 +215,29 @@ def __init__(self, format_string=None, **inputs):
210
215
def _rename (self ):
211
216
fmt_dict = dict ()
212
217
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 ])
214
224
if m :
215
225
fmt_dict .update (m .groupdict ())
216
226
for field in self .fmt_fields :
217
227
val = getattr (self .inputs , field )
218
228
if isdefined (val ):
219
229
fmt_dict [field ] = getattr (self .inputs , field )
220
230
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 ]])
222
233
else :
223
234
fmt_string = self .inputs .format_string
224
235
return fmt_string % fmt_dict
225
236
226
237
def _run_interface (self , runtime ):
227
238
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 ()))
229
241
return runtime
230
242
231
243
def _list_outputs (self ):
0 commit comments