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