@@ -48,10 +48,8 @@ def diff_values(compare1, compare2):
48
48
return True
49
49
elif type (compare1 ) != type (compare2 ):
50
50
return True
51
- elif compare1 != compare2 :
52
- return True
53
51
else :
54
- return False
52
+ return compare1 != compare2
55
53
56
54
57
55
def diff_header_fields (key , inputs ):
@@ -103,10 +101,19 @@ def diff_header_fields(key, inputs):
103
101
104
102
105
103
def get_headers_diff (files , opts ):
104
+ """
105
+ Getting the difference of headers.
106
+ Returns a dictionary that is later processed.
107
+
108
+ Parameters
109
+ ----------
110
+ files: list of files
111
+ opts: any options included from the command line
112
+ """
106
113
107
114
header_list = [nib .load (f ).header for f in files ]
108
115
109
- if opts .header_fields :
116
+ if opts .header_fields : # will almost always have a header field
110
117
# signals "all fields"
111
118
if opts .header_fields == 'all' :
112
119
# TODO: header fields might vary across file types, thus prior sensing would be needed
@@ -123,24 +130,27 @@ def get_headers_diff(files, opts):
123
130
output [f ] = val
124
131
125
132
return output
133
+ else :
134
+ return {}
126
135
127
136
128
137
def get_data_diff (files ):
129
138
130
139
data_list = [nib .load (f ).get_data () for f in files ]
131
- temp_bool = False
140
+ output = []
132
141
133
142
for a , b in itertools .combinations (data_list , 2 ):
134
- if diff_values (hashlib .md5 (repr (a ).encode ('utf-8' )).hexdigest (), hashlib .md5 (
135
- repr (b ).encode ('utf-8' )).hexdigest ()):
136
- temp_bool = True
137
- break
143
+ if diff_values (hash (str (a )), hash (str (b ))):
144
+ if hash (str (a )) not in output :
145
+ output .append (str (hash (str (a ))))
146
+ if hash (str (b )) not in output :
147
+ output .append (str (hash (str (b ))))
138
148
139
- return temp_bool
149
+ return output
140
150
141
151
142
152
def main ():
143
- """NO DAYS OFF """
153
+ """Getting the show on the road """
144
154
145
155
parser = get_opt_parser ()
146
156
(opts , files ) = parser .parse_args ()
@@ -153,38 +163,42 @@ def main():
153
163
# suppress nibabel format-compliance warnings
154
164
nib .imageglobals .logger .level = 50
155
165
156
- diff = get_headers_diff (files , opts )
157
- diff2 = get_data_diff (files )
166
+ header_diff = get_headers_diff (files , opts )
167
+ data_diff = get_data_diff (files )
158
168
159
- print ("{:<11}" .format ('Field' ), end = "" )
169
+ if len (data_diff ) != 0 and len (header_diff ) != 0 :
170
+ print ("{:<11}" .format ('Field' ), end = "" )
160
171
161
- for f in files :
162
- output = ""
163
- i = 0
164
- while i < len (f ):
165
- if f [i ] == "/" :
166
- output = ""
167
- else :
168
- output += f [i ]
169
- i += 1
172
+ for f in files :
173
+ output = ""
174
+ i = 0
175
+ while i < len (f ):
176
+ if f [i ] == "/" or f [ i ] == " \\ " :
177
+ output = ""
178
+ else :
179
+ output += f [i ]
180
+ i += 1
170
181
171
- print ("{:<45}" .format (output ), end = "" )
182
+ print ("{:<45}" .format (output ), end = "" )
172
183
173
- print ()
184
+ print ()
174
185
175
- for x in diff :
176
- print ("{:<11}" .format (x ), end = "" )
186
+ for x in header_diff :
187
+ print ("{:<11}" .format (x ), end = "" )
177
188
178
- for e in diff [x ]:
179
- print ("{:<45}" .format (e ), end = "" )
189
+ for e in header_diff [x ]:
190
+ print ("{:<45}" .format (e ), end = "" )
180
191
181
- print ()
192
+ print ()
182
193
183
194
print ("DATA: " , end = "" )
184
195
185
- if diff2 :
196
+ if len ( data_diff ) != 0 :
186
197
print ("These files are different." )
198
+ print ("{:<11}" .format ("Checksum" ), end = "" )
199
+ for i in data_diff :
200
+ print ("{:45}" .format (i [0 :8 ]), end = "" )
201
+ print ()
202
+ raise SystemExit (1 )
187
203
else :
188
204
print ("These files are identical!" )
189
-
190
- raise SystemExit (1 )
0 commit comments