Skip to content

Commit

Permalink
Merge pull request #1609 from totvs/release/v1.20.28
Browse files Browse the repository at this point in the history
Release/v1.20.28
  • Loading branch information
98llm authored Dec 6, 2024
2 parents e88c07a + cf32222 commit 7287d3b
Show file tree
Hide file tree
Showing 11 changed files with 648 additions and 482 deletions.
2 changes: 1 addition & 1 deletion scripts/install_package.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ taskkill /f /im chromedriver.exe
echo -------------------------
echo Installing project...
echo -------------------------
pip install -U dist/tir_framework-1.20.27.tar.gz
pip install -U dist/tir_framework-1.20.28.tar.gz
pause >nul | set/p = Press any key to exit ...
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@
'pyodbc==4.0.39',
'psutil==5.9.5',
'lxml==4.6.5',
'opencv-python==4.6.0.66',
'opencv-python==4.8.1.78',
'webdriver-manager'
],
packages=find_packages(),
Expand Down
6 changes: 2 additions & 4 deletions tir/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ class Webapp():
"""
def __init__(self, config_path="", autostart=True):
self.__webapp = WebappInternal(config_path, autostart)
self.__database = BaseDatabase(config_path, autostart=False)
self.config = ConfigLoader()
self.coverage = self.config.coverage

Expand Down Expand Up @@ -1279,7 +1278,7 @@ def QueryExecute(self, query, database_driver="", dbq_oracle_server="", database
>>> # Oracle Example:
>>> self.oHelper.QueryExecute("SELECT * FROM SA1T10", database_driver="Oracle in OraClient19Home1", dbq_oracle_server="Host:Port/oracle instance", database_server="SERVER_NAME", database_name="DATABASE_NAME", database_user="sa", database_password="123456")
"""
return self.__database.query_execute(query, database_driver, dbq_oracle_server, database_server, database_port, database_name, database_user, database_password)
return self.__webapp.query_execute(query, database_driver, dbq_oracle_server, database_server, database_port, database_name, database_user, database_password)

def GetConfigValue(self, json_key):
"""
Expand Down Expand Up @@ -1583,7 +1582,6 @@ class Poui():

def __init__(self, config_path="", autostart=True):
self.__poui = PouiInternal(config_path, autostart)
self.__database = BaseDatabase(config_path, autostart=False)
self.config = ConfigLoader()
self.coverage = self.config.coverage

Expand Down Expand Up @@ -1637,7 +1635,7 @@ def ClickCombo(self, field='', value='', position=1):
>>> oHelper.ClickCombo('Visão', 'Compras')
:return:
"""
self.__poui.click_poui_component(field, value, position, selector="div > po-combo", container=True)
self.__poui.click_combo(field, value, position)

def ClickSelect(self, field='', value='', position=1):
"""
Expand Down
23 changes: 23 additions & 0 deletions tir/technologies/core/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -782,6 +782,29 @@ def search_zindex(self,element):
zindex = int(element.attrs['style'].split("z-index:")[1].split(";")[0].strip())

return zindex

def collect_zindex(self, reverse=True):
"""
returns z-index list in decrescent order by default or in crescent order if reverse is False.
"""

soup = self.get_current_DOM()

style_elements = soup.find_all(style=True)

if style_elements:
zindex_list = list(filter(lambda x: 'z-index' in x['style'], style_elements))
if zindex_list:
zindex_list_filtered = list(map(lambda x: x.attrs['style'].split('z-index')[1].split(';')[0].split(':')[1].strip(), zindex_list))
return sorted(list(map(int, zindex_list_filtered)), reverse=reverse)

def return_last_zindex(self):
"""
returns the last z-index value in the page.
"""
zindex_list = self.collect_zindex(reverse=True)
if zindex_list:
return next(iter(zindex_list), None)

def select_combo(self, element, option, index=False, shadow_root=True, locator=False):
"""
Expand Down
50 changes: 12 additions & 38 deletions tir/technologies/core/base_database.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,13 @@
from tir.technologies.core.base import Base
from tir.technologies.webapp_internal import WebappInternal
import pandas as pd
import pyodbc
import re
from tir.technologies.core.logging_config import logger
from tir.technologies.core.config import ConfigLoader

class BaseDatabase:

class BaseDatabase(Base):

def __init__(self, config_path="", autostart=True):
super().__init__(config_path, autostart=False)
self.webapp_internal = WebappInternal(config_path, autostart=False)
self.restart_counter = self.webapp_internal.restart_counter
def __init__(self):
self.config = ConfigLoader()

def odbc_connect(self, database_driver="", dbq_oracle_server="", database_server="", database_port=1521, database_name="", database_user="", database_password=""):
"""
Expand All @@ -27,16 +23,10 @@ def odbc_connect(self, database_driver="", dbq_oracle_server="", database_server
database_password = self.config.database_password if not database_password else database_password
dbq_oracle_server = self.config.dbq_oracle_server if not dbq_oracle_server else dbq_oracle_server

self.check_pyodbc_drivers(database_driver)

try:
if dbq_oracle_server:
connection = pyodbc.connect(f'DRIVER={database_driver};dbq={dbq_oracle_server};database={database_name};uid={database_user};pwd={database_password}')
else:
connection = pyodbc.connect(f'DRIVER={database_driver};server={database_server};port={database_port};database={database_name};uid={database_user};pwd={database_password}')
except Exception as error:
self.webapp_internal.restart_counter = 3
self.webapp_internal.log_error(str(error))
if dbq_oracle_server:
connection = pyodbc.connect(f'DRIVER={database_driver};dbq={dbq_oracle_server};database={database_name};uid={database_user};pwd={database_password}')
else:
connection = pyodbc.connect(f'DRIVER={database_driver};server={database_server};port={database_port};database={database_name};uid={database_user};pwd={database_password}')

return connection

Expand All @@ -45,10 +35,7 @@ def test_odbc_connection(self, connection):
:param connection:
:return: cursor attribute if connection ok else return False
"""
try:
return connection.cursor()
except:
return False
return connection.cursor()

def connect_database(self, query="", database_driver="", dbq_oracle_server="", database_server="", database_port=1521, database_name="", database_user="", database_password=""):

Expand All @@ -74,15 +61,7 @@ def disconnect_database(self, connection):
logger().info('DataBase connection stopped')
else:
logger().info('DataBase connection already stopped')

def check_pyodbc_drivers(self, driver_database):
if not next(iter(list(
filter(lambda x: x == driver_database.lower(), list(map(lambda x: x.lower(), pyodbc.drivers()))))),
None):
error_message = f"Driver: '{driver_database}' isn't a valid driver name!"
self.webapp_internal.restart_counter = 3
self.webapp_internal.log_error(error_message)


def query_execute(self, query, database_driver, dbq_oracle_server, database_server, database_port, database_name, database_user, database_password):
"""
Return a dictionary if the query statement is a SELECT otherwise print a number of row
Expand Down Expand Up @@ -133,16 +112,11 @@ def query_execute(self, query, database_driver, dbq_oracle_server, database_serv
if re.findall(r'^(SELECT)', query.upper()):
df = pd.read_sql(sql=query, con=connection)
return (df.to_dict())
elif re.findall(r'^(UPDATE|DELETE|INSERT)', query.upper()):
self.cursor_execute(query, connection)
else:
self.webapp_internal.log_error(f"Not a valid query in {query}")
self.cursor_execute(query, connection)

def cursor_execute(self, query, connection):
cursor = connection.cursor()
try:
rowcount = cursor.execute(query).rowcount
except Exception as error:
self.webapp_internal.log_error(str(error))
rowcount = cursor.execute(query).rowcount
logger().info(f'{rowcount} row(s) affected')
connection.commit()
Loading

0 comments on commit 7287d3b

Please sign in to comment.