3
3
# vi: set ft=python sts=4 ts=4 sw=4 et:
4
4
"""
5
5
6
- Miscelanous tools to support Interface functionality
7
- ....................................................
6
+ Miscellaneous tools to support Interface functionality
7
+ ......................................................
8
8
9
9
"""
10
10
from __future__ import print_function , division , unicode_literals , absolute_import
11
- from builtins import range , object , open , str
11
+ from builtins import range , object , str
12
12
13
13
import os
14
14
from copy import deepcopy
18
18
19
19
from ... import logging
20
20
from ...utils .misc import is_container
21
- from ...utils .filemanip import md5 , to_str
21
+ from ...utils .filemanip import md5 , to_str , hash_infile
22
22
iflogger = logging .getLogger ('interface' )
23
23
24
24
@@ -116,27 +116,6 @@ def __repr__(self):
116
116
outstr .append (')' )
117
117
return '' .join (outstr )
118
118
119
- def _hash_infile (self , adict , key ):
120
- # Inject file hashes into adict[key]
121
- stuff = adict [key ]
122
- if not is_container (stuff ):
123
- stuff = [stuff ]
124
- file_list = []
125
- for afile in stuff :
126
- if os .path .isfile (afile ):
127
- md5obj = md5 ()
128
- with open (afile , 'rb' ) as fp :
129
- while True :
130
- data = fp .read (8192 )
131
- if not data :
132
- break
133
- md5obj .update (data )
134
- md5hex = md5obj .hexdigest ()
135
- else :
136
- md5hex = None
137
- file_list .append ((afile , md5hex ))
138
- return file_list
139
-
140
119
def _get_bunch_hash (self ):
141
120
"""Return a dictionary of our items with hashes for each file.
142
121
@@ -181,7 +160,7 @@ def _get_bunch_hash(self):
181
160
dict_withhash = self .dictcopy ()
182
161
dict_nofilename = self .dictcopy ()
183
162
for item in infile_list :
184
- dict_withhash [item ] = self . _hash_infile (dict_withhash , item )
163
+ dict_withhash [item ] = _hash_bunch_dict (dict_withhash , item )
185
164
dict_nofilename [item ] = [val [1 ] for val in dict_withhash [item ]]
186
165
# Sort the items of the dictionary, before hashing the string
187
166
# representation so we get a predictable order of the
@@ -208,6 +187,15 @@ def __pretty__(self, p, cycle):
208
187
p .end_group (6 , ')' )
209
188
210
189
190
+ def _hash_bunch_dict (adict , key ):
191
+ """Inject file hashes into adict[key]"""
192
+ stuff = adict [key ]
193
+ if not is_container (stuff ):
194
+ stuff = [stuff ]
195
+ return [(afile , hash_infile (afile ))
196
+ for afile in stuff ]
197
+
198
+
211
199
class InterfaceResult (object ):
212
200
"""Object that contains the results of running a particular Interface.
213
201
@@ -307,7 +295,7 @@ def load_template(name):
307
295
please use nipype.interfaces.fsl.model.load_template
308
296
309
297
"""
310
- from .fsl .model import load_template
298
+ from .. fsl .model import load_template
311
299
iflogger .warning (
312
300
'Deprecated in 1.0.0, and will be removed in 1.1.0, '
313
301
'please use nipype.interfaces.fsl.model.load_template instead.'
0 commit comments