Fix Impress examples

This commit is contained in:
Timothyxxx
2024-02-07 21:52:21 +08:00
parent 66304b3bab
commit 8dd62178be
9 changed files with 250 additions and 34 deletions

View File

@@ -13,6 +13,8 @@ def get_vm_command_line(env, config: Dict[str, str]):
response = requests.post(f"http://{vm_ip}:{port}/execute", json={"command": command, "shell": shell})
print(response.json())
if response.status_code == 200:
return response.json()["output"]
else:

View File

@@ -31,9 +31,7 @@ from .docs import (
evaluate_alignment,
get_unique_train_ids,
check_no_duplicates,
compare_init_lines
)
from .docs import (
compare_init_lines,
find_default_font,
contains_page_break,
compare_docx_files,
@@ -87,7 +85,8 @@ from .slides import (
evaluate_presentation_fill_to_rgb_distance,
check_left_panel,
check_transition,
check_page_number_colors
check_page_number_colors,
check_auto_saving_time
)
from .table import (
compare_table,

View File

@@ -46,7 +46,6 @@ def check_text_enlarged(scaling_factor_str):
def check_moved_jpgs(directory_list, rule):
expected_jpgs = rule["expected"]
moved_jpgs = [node['name'] for node in directory_list['children']]

View File

@@ -168,8 +168,6 @@ def compare_pptx_files(file1_path, file2_path, **options):
for para1, para2 in zip(shape1.text_frame.paragraphs, shape2.text_frame.paragraphs):
# check if the runs are the same
for run1, run2 in zip(para1.runs, para2.runs):
if run1.text != run2.text and examine_text:
return 0
# check if the font properties are the same
if run1.font.name != run2.font.name and examine_font_name:
@@ -190,7 +188,8 @@ def compare_pptx_files(file1_path, file2_path, **options):
if run1.font.underline != run2.font.underline and examine_font_underline:
return 0
if run1.font._element.attrib.get('strike', 'noStrike') != run2.font._element.attrib.get('strike', 'noStrike') and examine_strike_through:
if run1.font._element.attrib.get('strike', 'noStrike') != run2.font._element.attrib.get(
'strike', 'noStrike') and examine_strike_through:
return 0
# fixme: Actually there are more properties to be compared, but we cannot get them through pptx
@@ -371,6 +370,50 @@ def check_page_number_colors(pptx_file, rules):
return 1
def check_auto_saving_time(pptx_file, rules):
minutes = rules["minutes"]
# open and parse xml file
try:
tree = ET.parse(pptx_file)
root = tree.getroot()
# Traverse the XML tree to find the autosave time setting
autosave_time = None
for item in root.findall(".//item"):
# Check the path attribute
path = item.get('{http://openoffice.org/2001/registry}path')
if path == "/org.openoffice.Office.Common/Save/Document":
# Once the correct item is found, look for the prop element with the name "AutoSaveTimeIntervall"
for prop in item.findall(".//prop"):
name = prop.get('{http://openoffice.org/2001/registry}name')
if name == "AutoSaveTimeIntervall":
# Extract the value of the autosave time interval
autosave_time = prop.find(".//value").text
break
if autosave_time is None:
return 0
else:
autosave_time = int(autosave_time)
if autosave_time == minutes:
return 1
else:
return 0
except ET.ParseError as e:
logger.error(f"Error parsing XML: {e}")
except FileNotFoundError:
logger.error(f"File not found: {pptx_file}")
if __name__ == '__main__':
print(compare_pptx_files(r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\550ce7e7-747b-495f-b122-acdc4d0b8e54\New_Club_Spring_2018_Training_Gold.pptx", r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\550ce7e7-747b-495f-b122-acdc4d0b8e54\New_Club_Spring_2018_Training_Gold.pptx"))
# print(evaluate_presentation_fill_to_rgb_distance(r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\3b27600c-3668-4abd-8f84-7bcdebbccbdb\lec17-gui-events.pptx", {"rgb": (0, 0, 255)}))
# print(compare_pptx_files(
# r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\550ce7e7-747b-495f-b122-acdc4d0b8e54\New_Club_Spring_2018_Training_Gold.pptx",
# r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\550ce7e7-747b-495f-b122-acdc4d0b8e54\New_Club_Spring_2018_Training_Gold.pptx"))
# print(evaluate_presentation_fill_to_rgb_distance(r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\3b27600c-3668-4abd-8f84-7bcdebbccbdb\lec17-gui-events.pptx", {"rgb": (0, 0, 255)}))
# print(check_auto_saving_time(r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\2cd43775-7085-45d8-89fa-9e35c0a915cf\registrymodifications.xcu", {"minutes": 3}))
print(compare_pptx_files(r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\a669ef01-ded5-4099-9ea9-25e99b569840\Writing-Outlines.pptx",
r"C:\Users\tianbaox\Desktop\DesktopEnv\cache\a669ef01-ded5-4099-9ea9-25e99b569840\Writing-Outlines_Gold.pptx",
examine_shape=False))