From b0a4cac1c59e22cb109fa50fdf0d83af545c57a6 Mon Sep 17 00:00:00 2001 From: Tareq Date: Sun, 26 May 2024 16:13:17 +0600 Subject: [PATCH 1/3] Removed easyocr from requirement files --- requirements-linux.txt | 1 - requirements-mac.txt | 1 - requirements-win.txt | 1 - 3 files changed, 3 deletions(-) diff --git a/requirements-linux.txt b/requirements-linux.txt index b8c1a282a..2ac57f036 100644 --- a/requirements-linux.txt +++ b/requirements-linux.txt @@ -55,6 +55,5 @@ configobj jinja2 pandas pyperclip -easyocr thefuzz backports-datetime-fromisoformat; python_version < '3.11' \ No newline at end of file diff --git a/requirements-mac.txt b/requirements-mac.txt index c3217fd2c..2fe5a6cf5 100644 --- a/requirements-mac.txt +++ b/requirements-mac.txt @@ -60,5 +60,4 @@ jinja2 pandas pyperclip backports-datetime-fromisoformat; python_version < '3.11' -easyocr thefuzz \ No newline at end of file diff --git a/requirements-win.txt b/requirements-win.txt index 9af0eafad..aa87d5b80 100644 --- a/requirements-win.txt +++ b/requirements-win.txt @@ -70,5 +70,4 @@ jinja2 pandas pyperclip backports-datetime-fromisoformat; python_version < '3.11' -easyocr thefuzz \ No newline at end of file From 62a5b92ef48e898466ae6e8721f360ebd734da4a Mon Sep 17 00:00:00 2001 From: Tareq Date: Sun, 26 May 2024 16:14:07 +0600 Subject: [PATCH 2/3] Added function to auto install easyocr --- .../Desktop/CrossPlatform/BuiltInFunctions.py | 42 ++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/Framework/Built_In_Automation/Desktop/CrossPlatform/BuiltInFunctions.py b/Framework/Built_In_Automation/Desktop/CrossPlatform/BuiltInFunctions.py index df186a28e..0fd875bf5 100644 --- a/Framework/Built_In_Automation/Desktop/CrossPlatform/BuiltInFunctions.py +++ b/Framework/Built_In_Automation/Desktop/CrossPlatform/BuiltInFunctions.py @@ -1255,16 +1255,56 @@ def keystroke_for_element(data_set): reader = None +def install_easyocr(): + sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME + + # get the OS + pltform = platform.system() + + #check easyocr installment in Windows + if pltform == "Windows": + pip_command = ['pip', 'list'] + easyocr_search_command = ['findstr', 'easyocr'] + pip_process = subprocess.Popen(pip_command, stdout=subprocess.PIPE) + search_process = subprocess.Popen(easyocr_search_command, stdin=pip_process.stdout, stdout=subprocess.PIPE,text=True) + + is_easyocr, _ = search_process.communicate() + + if is_easyocr: + CommonUtil.ExecLog( + sModuleInfo, + "Easyocr is already installed", + 5, + ) + else: + CommonUtil.ExecLog( + sModuleInfo, + "Installing Easyocr", + 5, + ) + # os.system('echo y | pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pytesseract') + try: + result = subprocess.run( + ['pip', 'install', '--trusted-host', 'pypi.org', '--trusted-host', 'files.pythonhosted.org', 'easyocr'], + check=True, + text=True, + capture_output=True + ) + CommonUtil.ExecLog(sModuleInfo,f"{result.stdout}",5) + except subprocess.CalledProcessError as e: + print(f"Error occurred: {e.stderr}") + + # initialize the OCR def get_easyocr_reader(): sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME + install_easyocr() global reader if not reader: CommonUtil.ExecLog(sModuleInfo, "Initializing EasyOCR reader...", 1) reader = easyocr.Reader(['en']) else: CommonUtil.ExecLog(sModuleInfo, "EasyOCR reader already initialized.", 1) - return reader # create a list of texts def get_only_text(data:tuple): From 920340e5f94c0f400eb6fe5c9c4b78f209d0a123 Mon Sep 17 00:00:00 2001 From: Tareq Date: Sun, 26 May 2024 11:15:25 -0400 Subject: [PATCH 3/3] added part for linux/mac --- .../Desktop/CrossPlatform/BuiltInFunctions.py | 35 +++++++++++++++++-- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/Framework/Built_In_Automation/Desktop/CrossPlatform/BuiltInFunctions.py b/Framework/Built_In_Automation/Desktop/CrossPlatform/BuiltInFunctions.py index 0fd875bf5..f9310271b 100644 --- a/Framework/Built_In_Automation/Desktop/CrossPlatform/BuiltInFunctions.py +++ b/Framework/Built_In_Automation/Desktop/CrossPlatform/BuiltInFunctions.py @@ -17,7 +17,6 @@ True # https://pyautogui.readthedocs.io/en/latest/ from fileinput import filename import os, os.path, sys, time, inspect, subprocess -from turtle import right from Framework.Utilities import CommonUtil, FileUtilities as FL from Framework.Utilities.decorators import logger @@ -36,7 +35,6 @@ from Framework.Utilities import ConfigModule import traceback import platform -import easyocr from thefuzz import fuzz import threading from pathlib import Path @@ -1282,7 +1280,6 @@ def install_easyocr(): "Installing Easyocr", 5, ) - # os.system('echo y | pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org pytesseract') try: result = subprocess.run( ['pip', 'install', '--trusted-host', 'pypi.org', '--trusted-host', 'files.pythonhosted.org', 'easyocr'], @@ -1293,12 +1290,44 @@ def install_easyocr(): CommonUtil.ExecLog(sModuleInfo,f"{result.stdout}",5) except subprocess.CalledProcessError as e: print(f"Error occurred: {e.stderr}") + else: + pip_command = ['pip3', 'list'] + easyocr_search_command = ['grep', 'easyocr'] + pip_process = subprocess.Popen(pip_command, stdout=subprocess.PIPE) + search_process = subprocess.Popen(easyocr_search_command, stdin=pip_process.stdout, stdout=subprocess.PIPE,text=True) + + is_easyocr, _ = search_process.communicate() + + if is_easyocr: + CommonUtil.ExecLog( + sModuleInfo, + "Easyocr is already installed", + 5, + ) + else: + CommonUtil.ExecLog( + sModuleInfo, + "Installing Easyocr", + 5, + ) + try: + result = subprocess.run( + ['pip3', 'install', '--trusted-host', 'pypi.org', '--trusted-host', 'files.pythonhosted.org', 'easyocr'], + check=True, + text=True, + capture_output=True + ) + CommonUtil.ExecLog(sModuleInfo,f"{result.stdout}",5) + except subprocess.CalledProcessError as e: + print(f"Error occurred: {e.stderr}") + # initialize the OCR def get_easyocr_reader(): sModuleInfo = inspect.currentframe().f_code.co_name + " : " + MODULE_NAME install_easyocr() + import easyocr global reader if not reader: CommonUtil.ExecLog(sModuleInfo, "Initializing EasyOCR reader...", 1)