ver Jan17th

updated the existing task configs
This commit is contained in:
David Chang
2024-01-17 17:27:08 +08:00
parent 3f335f47c6
commit ffc4c32bac
23 changed files with 449 additions and 86 deletions

View File

@@ -298,11 +298,11 @@ class SetupController:
# TODO # TODO
raise NotImplementedError() raise NotImplementedError()
def _activate_window_setup(self, window_name: str): def _activate_window_setup(self, window_name: str, strict: bool = False, by_class: bool = False):
if not window_name: if not window_name:
raise Exception(f"Setup Open - Invalid path ({window_name}).") raise Exception(f"Setup Open - Invalid path ({window_name}).")
payload = json.dumps({"window_name": window_name}) payload = json.dumps({"window_name": window_name, "strict": strict, "by_class": by_class})
headers = { headers = {
'Content-Type': 'application/json' 'Content-Type': 'application/json'
} }
@@ -317,6 +317,25 @@ class SetupController:
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
logger.error("An error occurred while trying to send the request: %s", e) logger.error("An error occurred while trying to send the request: %s", e)
def _close_window_setup(self, window_name: str, strict: bool = False, by_class: bool = False):
if not window_name:
raise Exception(f"Setup Open - Invalid path ({window_name}).")
payload = json.dumps({"window_name": window_name, "strict": strict, "by_class": by_class})
headers = {
'Content-Type': 'application/json'
}
# send request to server to open file
try:
response = requests.post(self.http_server + "/setup" + "/close_window", headers=headers, data=payload)
if response.status_code == 200:
logger.info("Command executed successfully: %s", response.text)
else:
logger.error(f"Failed to close window {window_name}. Status code: %s", response.text)
except requests.exceptions.RequestException as e:
logger.error("An error occurred while trying to send the request: %s", e)
# Chrome setup # Chrome setup
def _chrome_open_tabs_setup(self, urls_to_open: List[str]): def _chrome_open_tabs_setup(self, urls_to_open: List[str]):
host = self.vm_ip host = self.vm_ip

View File

@@ -14,7 +14,7 @@ import pyautogui
import requests import requests
from PIL import Image from PIL import Image
from Xlib import display, X from Xlib import display, X
from flask import Flask, request, jsonify, send_file, abort, send_from_directory from flask import Flask, request, jsonify, send_file, abort #, send_from_directory
from lxml.etree import _Element from lxml.etree import _Element
from pyatspi import Accessible, StateType from pyatspi import Accessible, StateType
from pyatspi import Action as ATAction from pyatspi import Action as ATAction
@@ -579,39 +579,114 @@ def open_file():
def activate_window(): def activate_window():
data = request.json data = request.json
window_name = data.get('window_name', None) window_name = data.get('window_name', None)
if not window_name:
return "window_name required", 400
strict: bool = data.get("strict", False) # compare case-sensitively and match the whole string
by_class_name: bool = data.get("by_class", False)
os_name = platform.system() os_name = platform.system()
if os_name == 'Windows': if os_name == 'Windows':
import pygetwindow as gw import pygetwindow as gw
try: if by_class_name:
# Find the VS Code window return "Get window by class name is not supported on Windows currently.", 500
vscode_window = gw.getWindowsWithTitle(window_name)[0] windows: List[gw.Window] = gw.getWindowsWithTitle(window_name)
# Activate the window, bringing it to the front
vscode_window.activate() window: Optional[gw.Window] = None
except IndexError: if len(windows)==0:
return "VS Code window not found.", 404 return "Window {:} not found (empty results)".format(window_name), 404
elif strict:
for wnd in windows:
if wnd.title==wnd:
window = wnd
if window is None:
return "Window {:} not found (strict mode).".format(window_name), 404
else:
window = windows[0]
window.activate()
elif os_name == 'Darwin': elif os_name == 'Darwin':
import pygetwindow as gw import pygetwindow as gw
try: if by_class_name:
# Find the VS Code window return "Get window by class name is not supported on macOS currently.", 500
vscode_window = gw.getWindowsWithTitle(window_name)[0] # Find the VS Code window
# Un-minimize the window and then bring it to the front windows = gw.getWindowsWithTitle(window_name)
vscode_window.unminimize()
vscode_window.activate() window: Optional[gw.Window] = None
except IndexError: if len(windows)==0:
return "VS Code window not found.", 404 return "Window {:} not found (empty results)".format(window_name), 404
elif strict:
for wnd in windows:
if wnd.title==wnd:
window = wnd
if window is None:
return "Window {:} not found (strict mode).".format(window_name), 404
else:
window = windows[0]
# Un-minimize the window and then bring it to the front
window.unminimize()
window.activate()
elif os_name == 'Linux': elif os_name == 'Linux':
# Attempt to activate VS Code window using wmctrl # Attempt to activate VS Code window using wmctrl
subprocess.Popen(["wmctrl", "-a", window_name]) subprocess.run( [ "wmctrl"
, "-{:}{:}a".format( "x" if by_class_name else ""
, "F" if strict else ""
)
, window_name
]
)
else: else:
return f"Operating system {os_name} not supported.", 400 return f"Operating system {os_name} not supported.", 400
return "File opened successfully", 200 return "Window activated successfully", 200
@app.route("/setup/close_window", methods=["POST"])
def close_window():
data = request.json
if "window_name" not in data:
return "window_name required", 400
window_name: str = data["window_name"]
strict: bool = data.get("strict", False) # compare case-sensitively and match the whole string
by_class_name: bool = data.get("by_class", False)
os_name: str = platform.system()
if os_name == "Windows":
import pygetwindow as gw
if by_class_name:
return "Get window by class name is not supported on Windows currently.", 500
windows: List[gw.Window] = gw.getWindowsWithTitle(window_name)
window: Optional[gw.Window] = None
if len(windows)==0:
return "Window {:} not found (empty results)".format(window_name), 404
elif strict:
for wnd in windows:
if wnd.title==wnd:
window = wnd
if window is None:
return "Window {:} not found (strict mode).".format(window_name), 404
else:
window = windows[0]
window.close()
elif os_name == "Linux":
subprocess.run( [ "wmctrl"
, "-{:}{:}c".format( "x" if by_class_name else ""
, "F" if strict else ""
)
, window_name
]
)
elif os_name=="Darwin":
import pygetwindow as gw
return "Currently not supported on macOS.", 500
else:
return "Not supported platform {:}".format(os_name), 500
return "Window closed successfully.", 200
@app.route('/start_recording', methods=['POST']) @app.route('/start_recording', methods=['POST'])
def start_recording(): def start_recording():
@@ -639,7 +714,7 @@ def end_recording():
recording_process.terminate() recording_process.terminate()
recording_process.wait() recording_process.wait()
return_code = recording_process.returncode #return_code = recording_process.returncode
output, error = recording_process.communicate() output, error = recording_process.communicate()
recording_process = None recording_process = None

View File

@@ -27,6 +27,31 @@
"libreoffice_calc" "libreoffice_calc"
], ],
"evaluator": { "evaluator": {
"postconfig": [
{
"type": "activate_window",
"parameters": {
"window_name": "copy_sheet_insert.xlsx - LibreOffice Calc",
"strict": true
}
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
}
},
{
"type": "execute",
"parameters": {
"command": [
"python",
"-c",
"import pyautogui; pyautogui.press([\"ctrl\", \"s\"]);"
]
}
}
],
"func": "check_sheet_list", "func": "check_sheet_list",
"result": { "result": {
"type": "vm_file", "type": "vm_file",

View File

@@ -27,6 +27,31 @@
"libreoffice_calc" "libreoffice_calc"
], ],
"evaluator": { "evaluator": {
"postconfig": [
{
"type": "activate_window",
"parameters": {
"window_name": "Zoom_Out_Oversized_Cells.xlsx - LibreOffice Calc",
"strict": true
}
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
}
},
{
"type": "execute",
"parameters": {
"command": [
"python",
"-c",
"import pyautogui; pyautogui.press([\"ctrl\", \"s\"]);"
]
}
}
],
"func": "check_xlsx_zoom", "func": "check_xlsx_zoom",
"result": { "result": {
"type": "vm_file", "type": "vm_file",

View File

@@ -27,6 +27,31 @@
"libreoffice_calc" "libreoffice_calc"
], ],
"evaluator": { "evaluator": {
"postconfig": [
{
"type": "activate_window",
"parameters": {
"window_name": "Represent_in_millions_billions.xlsx - LibreOffice Calc",
"strict": true
}
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
}
},
{
"type": "execute",
"parameters": {
"command": [
"python",
"-c",
"import pyautogui; pyautogui.press([\"ctrl\", \"s\"]);"
]
}
}
],
"func": "compare_table", "func": "compare_table",
"result": { "result": {
"type": "vm_file", "type": "vm_file",

View File

@@ -26,6 +26,31 @@
"libreoffice calc" "libreoffice calc"
], ],
"evaluator": { "evaluator": {
"postconfig": [
{
"type": "activate_window",
"parameters": {
"window_name": "OrderId_Month_Chart.xlsx - LibreOffice Calc",
"strict": true
}
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
}
},
{
"type": "execute",
"parameters": {
"command": [
"python",
"-c",
"import pyautogui; pyautogui.press([\"ctrl\", \"s\"]);"
]
}
}
],
"func": "compare_table", "func": "compare_table",
"expected": { "expected": {
"type": "cloud_file", "type": "cloud_file",

View File

@@ -27,6 +27,31 @@
"libreoffice_calc" "libreoffice_calc"
], ],
"evaluator": { "evaluator": {
"postconfig": [
{
"type": "activate_window",
"parameters": {
"window_name": "Create_column_charts_using_statistics.xlsx - LibreOffice Calc",
"strict": true
}
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
}
},
{
"type": "execute",
"parameters": {
"command": [
"python",
"-c",
"import pyautogui; pyautogui.press([\"ctrl\", \"s\"]);"
]
}
}
],
"func": "compare_table", "func": "compare_table",
"result": { "result": {
"type": "vm_file", "type": "vm_file",

View File

@@ -27,6 +27,31 @@
"libreoffice_calc" "libreoffice_calc"
], ],
"evaluators": { "evaluators": {
"postconfig": [
{
"type": "activate_window",
"parameters": {
"window_name": "Freeze_row_column.xlsx - LibreOffice Calc",
"strict": true
}
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
}
},
{
"type": "execute",
"parameters": {
"command": [
"python",
"-c",
"import pyautogui; pyautogui.press([\"ctrl\", \"s\"]);"
]
}
}
],
"func": "check_xlsx_freeze", "func": "check_xlsx_freeze",
"result": { "result": {
"type": "vm_file", "type": "vm_file",

View File

@@ -27,6 +27,31 @@
"libreoffice_calc" "libreoffice_calc"
], ],
"evaluator": { "evaluator": {
"postconfig": [
{
"type": "activate_window",
"parameters": {
"window_name": "OrderId_Month_Chart.xlsx - LibreOffice Calc",
"strict": true
}
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
}
},
{
"type": "execute",
"parameters": {
"command": [
"python",
"-c",
"import pyautogui; pyautogui.press([\"ctrl\", \"s\"]);"
]
}
}
],
"func": "compare_table", "func": "compare_table",
"result": { "result": {
"type": "vm_file", "type": "vm_file",

View File

@@ -21,6 +21,31 @@
"libreoffice_calc" "libreoffice_calc"
], ],
"evaluator": { "evaluator": {
"postconfig": [
{
"type": "activate_window",
"parameters": {
"window_name": "Set_Decimal_Separator_Dot.xlsx - LibreOffice Calc",
"strict": true
}
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
}
},
{
"type": "execute",
"parameters": {
"command": [
"python",
"-c",
"import pyautogui; pyautogui.press([\"ctrl\", \"s\"]);"
]
}
}
],
"func": "check_libre_locale", "func": "check_libre_locale",
"result": { "result": {
"type": "vm_file", "type": "vm_file",

View File

@@ -30,8 +30,8 @@
"func": "check_pdf_pages", "func": "check_pdf_pages",
"result": { "result": {
"type": "vm_file", "type": "vm_file",
"path": "/home/user/Resize_Cells_Fit_Page.xlsx", "path": "/home/user/Resize_Cells_Fit_Page.pdf",
"dest": "Resize_Cells_Fit_Page.xlsx" "dest": "Resize_Cells_Fit_Page.pdf"
}, },
"expected": { "expected": {
"type": "rule", "type": "rule",

View File

@@ -27,6 +27,31 @@
"libreoffice calc" "libreoffice calc"
], ],
"evaluator": { "evaluator": {
"postconfig": [
{
"type": "activate_window",
"parameters": {
"window_name": "Quarterly_Product_Sales_by_Zone.xlsx - LibreOffice Calc",
"strict": true
}
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
}
},
{
"type": "execute",
"parameters": {
"command": [
"python",
"-c",
"import pyautogui; pyautogui.press([\"ctrl\", \"s\"]);"
]
}
}
],
"func": "compare_table", "func": "compare_table",
"expected": { "expected": {
"type": "cloud_file", "type": "cloud_file",

View File

@@ -45,12 +45,17 @@
"evaluator": { "evaluator": {
"postconfig": [ "postconfig": [
{ {
"type": "command", "type": "close_window",
"parameters": { "parameters": {
"command": ["wmctrl", "-xFc", "Mail.thunderbird"], "window_name": "Mail.thunderbird",
"until": { "strict": true,
"returncode": 1 "by_class": true
} }
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
} }
} }
], ],

View File

@@ -45,12 +45,16 @@
"evaluator": { "evaluator": {
"postconfig": [ "postconfig": [
{ {
"type": "command", "type": "close_window",
"parameters": { "parameters": {
"command": ["wmctrl", "-Fc", "Message Filters"], "window_name": "Message Filters",
"until": { "strict": true
"returncode": 1 }
} },
{
"type": "sleep",
"parameters": {
"seconds": 0.5
} }
} }
], ],

View File

@@ -45,16 +45,17 @@
"evaluator": { "evaluator": {
"postconfig": [ "postconfig": [
{ {
"type": "execute", "type": "close_window",
"parameters": { "parameters": {
"command": [ "window_name": "Mail.thunderbird",
"wmctrl", "strict": true,
"-xFc", "by_class": true
"Mail.thunderbird" }
], },
"until": { {
"returncode": 1 "type": "sleep",
} "parameters": {
"seconds": 0.5
} }
} }
], ],

View File

@@ -23,16 +23,17 @@
"evaluator": { "evaluator": {
"postconfig": [ "postconfig": [
{ {
"type": "execute", "type": "close_window",
"parameters": { "parameters": {
"command": [ "window_name": "Mail.thunderbird",
"wmctrl", "strict": true,
"-xFc", "by_class": true
"Mail.thunderbird" }
], },
"until": { {
"returncode": 1 "type": "sleep",
} "parameters": {
"seconds": 0.5
} }
} }
], ],

View File

@@ -45,12 +45,17 @@
"evaluator": { "evaluator": {
"postconfig": [ "postconfig": [
{ {
"type": "command", "type": "close_window",
"parameters": { "parameters": {
"command": ["wmctrl", "-xFc", "Mail.thunderbird"], "window_name": "Mail.thunderbird",
"until": { "strict": true,
"returncode": 1 "by_class": true
} }
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
} }
} }
], ],

View File

@@ -45,12 +45,17 @@
"evaluator": { "evaluator": {
"postconfig": [ "postconfig": [
{ {
"type": "command", "type": "close_window",
"parameters": { "parameters": {
"command": ["wmctrl", "-xFc", "Mail.thunderbird"], "window_name": "Mail.thunderbird",
"until": { "strict": true,
"returncode": 1 "by_class": true
} }
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
} }
} }
], ],

View File

@@ -23,12 +23,17 @@
"evaluator": { "evaluator": {
"postconfig": [ "postconfig": [
{ {
"type": "command", "type": "close_window",
"parameters": { "parameters": {
"command": ["wmctrl", "-xFc", "Mail.thunderbird"], "window_name": "Mail.thunderbird",
"until": { "strict": true,
"returncode": 1 "by_class": true
} }
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
} }
} }
], ],

View File

@@ -45,12 +45,17 @@
"evaluator": { "evaluator": {
"postconfig": [ "postconfig": [
{ {
"type": "command", "type": "close_window",
"parameters": { "parameters": {
"command": ["wmctrl", "-xFc", "Mail.thunderbird"], "window_name": "Mail.thunderbird",
"until": { "strict": true,
"returncode": 1 "by_class": true
} }
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
} }
} }
], ],

View File

@@ -45,12 +45,17 @@
"evaluator": { "evaluator": {
"postconfig": [ "postconfig": [
{ {
"type": "command", "type": "close_window",
"parameters": { "parameters": {
"command": ["wmctrl", "-xFc", "Mail.thunderbird"], "window_name": "Mail.thunderbird",
"until": { "strict": true,
"returncode": 1 "by_class": true
} }
},
{
"type": "sleep",
"parameters": {
"seconds": 0.5
} }
} }
], ],

View File

@@ -45,12 +45,16 @@
"evaluator": { "evaluator": {
"postconfig": [ "postconfig": [
{ {
"type": "command", "type": "close_window",
"parameters": { "parameters": {
"command": ["wmctrl", "-Fc", "Message Filters"], "window_name": "Message Filters",
"until": { "strict": true
"returncode": 1 }
} },
{
"type": "sleep",
"parameters": {
"seconds": 0.5
} }
} }
], ],

View File

@@ -23,12 +23,16 @@
"evaluator": { "evaluator": {
"postconfig": [ "postconfig": [
{ {
"type": "command", "type": "close_window",
"parameters": { "parameters": {
"command": ["wmctrl", "-Fc", "Message Filters"], "window_name": "Message Filters",
"until": { "strict": true
"returncode": 1 }
} },
{
"type": "sleep",
"parameters": {
"seconds": 0.5
} }
} }
], ],