add eval libreoffice writer compare image & centering & check file existence
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from .table import compare_table
|
||||
from .table import check_sheet_list, check_xlsx_freeze, check_zoom
|
||||
from .docs import find_default_font, contains_page_break, compare_docx_files, compare_docx_tables, compare_line_spacing, compare_insert_equation
|
||||
from .docs import compare_font_names, compare_subscript_contains, has_page_numbers_in_footers
|
||||
from .docs import compare_font_names, compare_subscript_contains, has_page_numbers_in_footers
|
||||
from .docs import is_first_line_centered, check_file_exists, compare_contains_image
|
||||
@@ -146,6 +146,30 @@ def has_page_numbers_in_footers(docx_file):
|
||||
return 0
|
||||
return 1
|
||||
|
||||
from docx.enum.text import WD_PARAGRAPH_ALIGNMENT
|
||||
|
||||
def is_first_line_centered(docx_file):
|
||||
doc = Document(docx_file)
|
||||
first_paragraph = doc.paragraphs[0]
|
||||
|
||||
# check if the first line is center justified
|
||||
return 1 if first_paragraph.paragraph_format.alignment == WD_PARAGRAPH_ALIGNMENT.CENTER else 0
|
||||
|
||||
import os
|
||||
def check_file_exists(directory, filename):
|
||||
|
||||
file_path = os.path.join(directory, filename)
|
||||
return 1 if os.path.isfile(file_path) else 0
|
||||
|
||||
def compare_contains_image(docx_file1, docx_file2):
|
||||
doc1 = Document(docx_file1)
|
||||
doc2 = Document(docx_file2)
|
||||
|
||||
for para1, para2 in zip(doc1.paragraphs, doc2.paragraphs):
|
||||
for run1, run2 in zip(para1.runs, para2.runs):
|
||||
if ('graphicData' in run1._element.xml and 'graphicData' not in run2._element.xml) or ('graphicData' not in run1._element.xml and 'graphicData' in run2._element.xml):
|
||||
return 0
|
||||
return 1
|
||||
|
||||
# file1 = 'path/to/file1.docx'
|
||||
# file2 = 'path/to/file2.docx'
|
||||
|
||||
@@ -3,10 +3,35 @@
|
||||
"snapshot": "libreoffice_writer",
|
||||
"instruction": "center-justify the first line",
|
||||
"source": "https://askubuntu.com/questions/1066351/how-do-you-center-align-in-libreoffice#:~:text=Ctrl%20%2B%20e%20will%20Center%20align%20the%20cursor%20for%20you.",
|
||||
"config": [],
|
||||
"config": [
|
||||
{
|
||||
"type": "download",
|
||||
"parameters": {
|
||||
"files": [
|
||||
{
|
||||
"url": "https://drive.google.com/uc?export=download&id=1C8iti3eSCY8xWHzA_iUSNqNyj6Nop0Tbw8odSSFe83U",
|
||||
"path": "Desktop/Centering_First_Line.docx"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "open",
|
||||
"parameters": {
|
||||
"path": "Desktop/Centering_First_Line.docx"
|
||||
}
|
||||
}
|
||||
],
|
||||
"trajectory": "trajectories/",
|
||||
"related_apps": [
|
||||
"libreoffice_writer"
|
||||
],
|
||||
"evaluator": "evaluation_dir"
|
||||
}
|
||||
"evaluator": {
|
||||
"func": "is_first_line_centered",
|
||||
"result": {
|
||||
"type": "vm_file",
|
||||
"path": "Desktop/Centering_First_Line.docx",
|
||||
"dest": "Centering_First_Line.docx"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,32 @@
|
||||
"snapshot": "libreoffice_writer",
|
||||
"instruction": "Export the current document into PDF, keep the file name",
|
||||
"source": "https://www.libreofficehelp.com/save-export-writer-documents-in-pdf-epub-format/",
|
||||
"config": [],
|
||||
"config": [
|
||||
{
|
||||
"type": "download",
|
||||
"parameters": {
|
||||
"files": [
|
||||
{
|
||||
"url": "https://drive.google.com/uc?export=download&id=15OtwtRFSdgyHokESupem6dBvtPeiWyKoZ7Pk5pmdzQc",
|
||||
"path": "Desktop/Save_Writer_PDF.docx"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "open",
|
||||
"parameters": {
|
||||
"path": "Desktop/Save_Writer_PDF.docx"
|
||||
}
|
||||
}
|
||||
],
|
||||
"trajectory": "trajectories/",
|
||||
"related_apps": [
|
||||
"libreoffice_writer"
|
||||
],
|
||||
"evaluator": "evaluation_dir"
|
||||
}
|
||||
"evaluator": {
|
||||
"func": "check_file_exists",
|
||||
"file_name": "Save_Writer_PDF.pdf",
|
||||
"directory": "/home/user/Downloads/"
|
||||
}
|
||||
}
|
||||
@@ -3,10 +3,40 @@
|
||||
"snapshot": "libreoffice_writer",
|
||||
"instruction": "Insert the image which is in IMAGE_PATH where my cursor is",
|
||||
"source": "https://www.quora.com/How-do-you-insert-images-into-a-LibreOffice-Writer-document",
|
||||
"config": [],
|
||||
"config": [
|
||||
{
|
||||
"type": "download",
|
||||
"parameters": {
|
||||
"files": [
|
||||
{
|
||||
"url": "https://drive.google.com/uc?export=download&id=1w-qFGreAkM0WMr5KufvhlOZfz8zonUJm5_7c7ybTOQ8",
|
||||
"path": "Desktop/Insert_Image_At_Cursor.docx"
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"type": "open",
|
||||
"parameters": {
|
||||
"path": "Desktop/Insert_Image_At_Cursor.docx"
|
||||
}
|
||||
}
|
||||
],
|
||||
"trajectory": "trajectories/",
|
||||
"related_apps": [
|
||||
"libreoffice_writer"
|
||||
],
|
||||
"evaluator": "evaluation_dir"
|
||||
}
|
||||
"evaluator": {
|
||||
"func": "compare_contains_image",
|
||||
"expected": {
|
||||
"type": "cloud_file",
|
||||
"path": "https://drive.google.com/uc?export=download&id=173TNJMWZ7AoNIGS9CRUcmyQUGutvAQ-rcYinY9wKanQ",
|
||||
"dest": "Insert_Image_At_Cursor_Gold.docx"
|
||||
},
|
||||
"result": {
|
||||
"type": "vm_file",
|
||||
"path": "Desktop/Insert_Image_At_Cursor.docx",
|
||||
"dest": "Insert_Image_At_Cursor.docx"
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user