@@ -1012,6 +1012,19 @@ def generate_visualization(testcase: Testcase, bar: ProgressBar):
1012
1012
assert in_path .is_file ()
1013
1013
assert ans_path .is_file ()
1014
1014
1015
+ feedbackdir = in_path .with_suffix (".feedbackdir" )
1016
+ image_files = [f"judgeimage{ ext } " for ext in config .KNOWN_VISUALIZER_EXTENSIONS ] + [
1017
+ f"teamimage{ ext } " for ext in config .KNOWN_VISUALIZER_EXTENSIONS
1018
+ ]
1019
+
1020
+ def use_feedback_image (feedbackdir : Path , source : str ) -> None :
1021
+ for name in image_files :
1022
+ path = feedbackdir / name
1023
+ if path .exists ():
1024
+ ensure_symlink (in_path .with_suffix (path .suffix ), path )
1025
+ bar .log (f"Using { name } from { source } as visualization" )
1026
+ return
1027
+
1015
1028
visualizer : Optional [visualize .AnyVisualizer ] = problem .visualizer (
1016
1029
visualize .InputVisualizer
1017
1030
)
@@ -1025,7 +1038,9 @@ def generate_visualization(testcase: Testcase, bar: ProgressBar):
1025
1038
out_path = ans_path
1026
1039
1027
1040
if visualizer is None :
1028
- # copy potential teamimage/judgeimage from output validator?
1041
+ for ext in config .KNOWN_VISUALIZER_EXTENSIONS :
1042
+ in_path .with_suffix (ext ).unlink (True )
1043
+ use_feedback_image (feedbackdir , "validator" )
1029
1044
return True
1030
1045
1031
1046
visualizer_args = testcase .testdata_yaml_args (visualizer , bar )
@@ -1043,16 +1058,13 @@ def generate_visualization(testcase: Testcase, bar: ProgressBar):
1043
1058
if isinstance (visualizer , visualize .InputVisualizer ):
1044
1059
result = visualizer .run (in_path , ans_path , cwd )
1045
1060
else :
1046
- feedbackdir = in_path .with_suffix (".feedbackdir" )
1047
1061
feedbackcopy = in_path .with_suffix (".feedbackcopy" )
1048
1062
shutil .rmtree (feedbackcopy )
1049
- shutil .copytree (feedbackdir , feedbackcopy )
1050
- teamimage = feedbackcopy / "teamimage"
1051
- judgeimage = feedbackcopy / "judgeimage"
1052
1063
1053
- for ext in config .KNOWN_VISUALIZER_EXTENSIONS :
1054
- teamimage .with_suffix (ext ).unlink (True )
1055
- judgeimage .with_suffix (ext ).unlink (True )
1064
+ def skip_images (src : str , content : list [str ]) -> list [str ]:
1065
+ return [] if src != str (feedbackdir ) else image_files
1066
+
1067
+ shutil .copytree (feedbackdir , feedbackcopy , ignore = skip_images )
1056
1068
1057
1069
result = visualizer .run (
1058
1070
in_path ,
@@ -1062,19 +1074,7 @@ def generate_visualization(testcase: Testcase, bar: ProgressBar):
1062
1074
visualizer_args ,
1063
1075
)
1064
1076
if result .status :
1065
- found = None
1066
- for ext in config .KNOWN_VISUALIZER_EXTENSIONS :
1067
- file = teamimage .with_suffix (ext )
1068
- if file .is_file ():
1069
- found = file
1070
- for ext in config .KNOWN_VISUALIZER_EXTENSIONS :
1071
- file = judgeimage .with_suffix (ext )
1072
- if file .is_file ():
1073
- found = file
1074
- if found is not None :
1075
- found .rename (in_path .with_suffix (found .suffix ))
1076
- bar .log (f"Using { found .name } from output_visualizer as visualization" )
1077
- shutil .rmtree (feedbackcopy )
1077
+ use_feedback_image (feedbackdir , "output_visualizer" )
1078
1078
1079
1079
if result .status == ExecStatus .TIMEOUT :
1080
1080
bar .debug (f"{ Style .RESET_ALL } -> { shorten_path (problem , cwd )} " )
0 commit comments