Skip to content

Commit fef7dc5

Browse files
committed
Pass hashmethod to associated copyfiles, PEP8 cleanup
1 parent 58e31d0 commit fef7dc5

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

nipype/utils/filemanip.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import numpy as np
2121

2222
from .misc import is_container
23-
from .config import mkdir_p
2423
from ..external.six import string_types
2524
from ..interfaces.traits_extension import isdefined
2625

@@ -246,10 +245,10 @@ def copyfile(originalfile, newfile, copy=False, create_new=False,
246245
elif hashmethod == 'content':
247246
hashfn = hash_infile
248247
newhash = hashfn(newfile)
249-
fmlogger.debug("File: %s already exists,%s, copy:%d"
250-
% (newfile, newhash, copy))
248+
fmlogger.debug("File: %s already exists,%s, copy:%d" %
249+
(newfile, newhash, copy))
251250
orighash = hashfn(originalfile)
252-
keep = hashfn(newfile) == hashfn(originalfile)
251+
keep = newhash == orighash
253252
if keep:
254253
fmlogger.debug("File: %s already exists, not overwriting, copy:%d"
255254
% (newfile, copy))
@@ -267,7 +266,7 @@ def copyfile(originalfile, newfile, copy=False, create_new=False,
267266
# Use realpath to avoid hardlinking symlinks
268267
os.link(os.path.realpath(originalfile), newfile)
269268
except OSError:
270-
use_hardlink=False # Disable for associated files
269+
use_hardlink = False # Disable hardlink for associated files
271270
else:
272271
keep = True
273272

@@ -276,7 +275,7 @@ def copyfile(originalfile, newfile, copy=False, create_new=False,
276275
fmlogger.debug("Symlinking File: %s->%s" % (newfile, originalfile))
277276
os.symlink(originalfile, newfile)
278277
except OSError:
279-
copy = True # Disable for associated files
278+
copy = True # Disable symlink for associated files
280279
else:
281280
keep = True
282281

@@ -294,12 +293,15 @@ def copyfile(originalfile, newfile, copy=False, create_new=False,
294293
matofile = originalfile[:-4] + ".mat"
295294
if os.path.exists(matofile):
296295
matnfile = newfile[:-4] + ".mat"
297-
copyfile(matofile, matnfile, copy, use_hardlink=use_hardlink)
298-
copyfile(hdrofile, hdrnfile, copy, use_hardlink=use_hardlink)
296+
copyfile(matofile, matnfile, copy, hashmethod=hashmethod,
297+
use_hardlink=use_hardlink)
298+
copyfile(hdrofile, hdrnfile, copy, hashmethod=hashmethod,
299+
use_hardlink=use_hardlink)
299300
elif originalfile.endswith(".BRIK"):
300301
hdrofile = originalfile[:-5] + ".HEAD"
301302
hdrnfile = newfile[:-5] + ".HEAD"
302-
copyfile(hdrofile, hdrnfile, copy, use_hardlink=use_hardlink)
303+
copyfile(hdrofile, hdrnfile, copy, hashmethod=hashmethod,
304+
use_hardlink=use_hardlink)
303305

304306
return newfile
305307

0 commit comments

Comments
 (0)