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