191def update_reference_files(actually_update=True, update_local_files=False):
192 print
193 print(
'Updating reference files')
194 print(
'========================')
195 commands = []
196 for branch, tests in failing_tests.items():
197 for test in tests:
198 print(
'Processing test: {} on branch {}'.format(test.name, branch))
199 if test.type == 'DiffPool':
200 print(
' * This is a DiffPool test, and currently has version {} of {}. Will update References.py with new version.'.format(test.existing_version, test.tag))
201 if actually_update:
202 print(
' -> The new version is: {}. Creating directory and copying files on EOS now.'.format(test.new_version))
203 create_dir_and_copy_refs(test, True)
204 else:
205
206 commands.extend(create_dir_and_copy_refs(test, False))
207
208 commands = list(dict.fromkeys(commands))
209
210
211 if update_local_files:
212 data = []
213 if debug:
214 print ('Updating local References.py file with new version {} for tag {}'.format(test.new_version, test.tag))
215 line_found = False
216 with open('Tools/WorkflowTestRunner/python/References.py', 'r') as f:
217 lines = f.readlines()
218 for line in lines:
219 if test.tag in line:
220 if test.existing_version in line:
221 line = line.replace(test.existing_version, test.new_version)
222 else:
224 print(
'** WARNING: For tag {} we were looking for existing version {}, but the line in the file is: {}'.format(test.tag, test.existing_version, line), end=
'')
225 print(
'** Are you sure your branch is up-to-date with main? We cannot update an older version of References.py!')
226 line_found = True
227 data.append(line)
228
229 if not line_found:
230 print(
'** WARNING - no matching line was found for the AMI tag {} in References.py. Are you sure your branch is up-to-date with main? We cannot update an older version of References.py!'.format(test.tag))
231
232 with open('Tools/WorkflowTestRunner/python/References.py', 'w') as f:
233 f.writelines(data)
234 elif test.type == 'Digest' and update_local_files:
235 print(
' * This is a Digest test. Need to update reference file {}.'.format(test.existing_ref))
236 data = []
237
238 diff_line=0
239 with open('Tools/PROCTools/data/'+test.existing_ref, 'r') as f:
240 lines = f.readlines()
241 for current_line, line in enumerate(lines):
242 split_curr_line = line.split()
243 if (split_curr_line[0] == 'run'):
244 data.append(line)
245 continue
246
247
248 if (not split_curr_line[0].isnumeric()) or (not split_curr_line[1].isnumeric()):
249 print(
'FATAL: Found a line in current digest which does not start with run/event numbers: {}'.format(line))
250 sys.exit(1)
251
252 split_old_diff_line = test.digest_old[diff_line].
split()
253 split_old_diff_line.pop(0)
254 split_new_diff_line = test.digest_new[diff_line].
split()
255 split_new_diff_line.pop(0)
256
257
258 if split_curr_line[0] == split_old_diff_line[0] and split_curr_line[1] == split_old_diff_line[1]:
259
260 if split_curr_line!=split_old_diff_line:
261 print(
'FATAL: It seems like this line was already changed.')
262 print(
'Line we expected: {}'.format(test.old_diff_lines[diff_line]))
263 print(
'Line we got : {}'.format(line))
264 sys.exit(1)
265
266
267 if split_curr_line[0] == split_new_diff_line[0] and split_curr_line[1] == split_new_diff_line[1]:
268
269 data.append("".join(["{:>12}".format(x) for x in split_new_diff_line])+ '\n')
270 if ((diff_line+1)<len(test.digest_old)):
271 diff_line+=1
272 continue
273
274
275 data.append(line)
276
277 print(
' -> Updating PROCTools digest file {}'.format(test.existing_ref))
278 with open('Tools/PROCTools/data/'+test.existing_ref, 'w') as f:
279 f.writelines(data)
280 return commands
281
282