@@ -117,6 +117,50 @@ def get_data_md5sums(files):
117
117
return md5sums
118
118
119
119
120
+ def display_diff (files , diff ):
121
+ """Format header differences into a nice string
122
+
123
+ Parameters
124
+ ----------
125
+ files: list of files that were compared so we can print their names
126
+ diff: dict of different valued header fields
127
+
128
+ Returns
129
+ -------
130
+ str
131
+ string-formatted table of differences
132
+ """
133
+ output = ""
134
+ field_width = "{:<15}"
135
+ value_width = "{:<55}"
136
+
137
+ output += "These files are different.\n "
138
+ output += field_width .format ('Field' )
139
+
140
+ for f in files :
141
+ output += value_width .format (os .path .basename (f ))
142
+
143
+ output += "\n "
144
+
145
+ for key , value in diff .items ():
146
+ output += field_width .format (key )
147
+
148
+ for item in value :
149
+ item_str = str (item )
150
+ # Value might start/end with some invisible spacing characters so we
151
+ # would "condition" it on both ends a bit
152
+ item_str = re .sub ('^[ \t ]+' , '<' , item_str )
153
+ item_str = re .sub ('[ \t ]+$' , '>' , item_str )
154
+ # and also replace some other invisible symbols with a question
155
+ # mark
156
+ item_str = re .sub ('[\x00 ]' , '?' , item_str )
157
+ output += value_width .format (item_str )
158
+
159
+ output += "\n "
160
+
161
+ return output
162
+
163
+
120
164
def main ():
121
165
"""Getting the show on the road"""
122
166
@@ -148,30 +192,8 @@ def main():
148
192
diff ['DATA(md5)' ] = data_diff
149
193
150
194
if diff :
151
- print ("These files are different." )
152
- print ("{:<15}" .format ('Field' ), end = "" )
153
-
154
- for f in files :
155
- print ("{:<55}" .format (os .path .basename (f )), end = "" )
156
-
157
- print ()
158
-
159
- for key , value in diff .items ():
160
- print ("{:<15}" .format (key ), end = "" )
161
-
162
- for item in value :
163
- item_str = str (item )
164
- # Value might start/end with some invisible spacing characters so we
165
- # would "condition" it on both ends a bit
166
- item_str = re .sub ('^[ \t ]+' , '<' , item_str )
167
- item_str = re .sub ('[ \t ]+$' , '>' , item_str )
168
- # and also replace some other invisible symbols with a question
169
- # mark
170
- item_str = re .sub ('[\x00 ]' , '?' , item_str )
171
- print ("{:<55}" .format (item_str ), end = "" )
172
-
173
- print ()
174
-
195
+ sys .stdout .write (display_diff (files , diff ))
175
196
raise SystemExit (1 )
197
+
176
198
else :
177
199
print ("These files are identical." )
0 commit comments