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