Skip to content

Commit b611b0d

Browse files
authored
Merge pull request #623 from AutomationSolutionz/req-42-database-android-web-password
[REQ-42] Added Android, Database and Web detection and installation functions to the Node integrated installer
2 parents 9cf7683 + 07babed commit b611b0d

31 files changed

Lines changed: 10082 additions & 177 deletions

Framework/Built_In_Automation/Database/BuiltInFunctions.py

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -277,32 +277,29 @@ def db_get_connection(session_name):
277277
)
278278
CommonUtil.ExecLog(sModuleInfo, "Connected to Snowflake.", 1)
279279
elif "oracle" in db_type:
280-
import cx_Oracle
281-
282-
# https://cx-oracle.readthedocs.io/en/latest/api_manual/module.html#cx_Oracle.makedsn
283-
if db_sid != 'zeuz_failed':
284-
dsn = cx_Oracle.makedsn(
285-
host=db_host,
286-
port=db_port,
287-
sid=db_sid
288-
)
289-
elif db_service_name != 'zeuz_failed':
290-
dsn = cx_Oracle.makedsn(
291-
host=db_host,
292-
port=db_port,
293-
service_name=db_service_name
294-
)
280+
import oracledb
281+
282+
# Construct the DSN (Data Source Name) using the Easy Connect syntax
283+
dsn = None
284+
if db_service_name and db_service_name != 'zeuz_failed':
285+
# Use Service Name for connection: host:port/service_name
286+
dsn = f"{db_host}:{db_port}/{db_service_name}"
287+
elif db_sid and db_sid != 'zeuz_failed':
288+
# Use SID for connection: host:port:sid
289+
dsn = f"{db_host}:{db_port}:{db_sid}"
295290
else:
296-
CommonUtil.ExecLog(sModuleInfo, "Either db_sid or db_service must be provide.", 3)
291+
CommonUtil.ExecLog(sModuleInfo, "Either db_sid or db_service must be provided.", 3)
297292
return "zeuz_failed"
293+
294+
CommonUtil.ExecLog(sModuleInfo, f"Attempting Oracle connection using DSN: {dsn}", 1)
298295

299296
# Connect to db
300-
# https://cx-oracle.readthedocs.io/en/latest/api_manual/module.html#cx_Oracle.connect
301-
db_con = cx_Oracle.connect(
297+
db_con = oracledb.connect(
302298
user=db_user_id,
303299
password=db_password,
304300
dsn=dsn,
305301
)
302+
CommonUtil.ExecLog(sModuleInfo, "Connected to Oracle using python-oracledb.", 1)
306303
else:
307304
import pyodbc
308305

Lines changed: 127 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,131 @@
1-
async def check_status():
2-
print("[adb] Checking status...")
1+
import subprocess
2+
import asyncio
3+
import platform
4+
import os
5+
from Framework.install_handler.utils import send_response
6+
7+
8+
async def check_status() -> bool:
9+
"""Check if ADB (Android Debug Bridge) is installed."""
10+
print("[installer][android-adb] Checking status...")
11+
12+
# Dynamically refresh ANDROID_HOME and PATH from registry on Windows
13+
system = platform.system()
14+
if system == "Windows":
15+
try:
16+
import winreg
17+
with winreg.OpenKey(winreg.HKEY_CURRENT_USER, r"Environment", 0, winreg.KEY_READ) as key:
18+
try:
19+
android_home_reg, _ = winreg.QueryValueEx(key, "ANDROID_HOME")
20+
if android_home_reg:
21+
# Expand environment variables before checking if path exists
22+
android_home_expanded = os.path.expandvars(android_home_reg)
23+
if os.path.exists(android_home_expanded):
24+
os.environ['ANDROID_HOME'] = android_home_expanded
25+
# Update PATH with platform-tools (where ADB is located)
26+
platform_tools = os.path.join(android_home_expanded, "platform-tools")
27+
current_path = os.environ.get('PATH', '')
28+
if platform_tools not in current_path:
29+
os.environ['PATH'] = f"{platform_tools};{current_path}"
30+
print(f"[installer][android-adb] Refreshed ANDROID_HOME from registry: {android_home_expanded}")
31+
except FileNotFoundError:
32+
pass
33+
34+
# Also check ANDROID_SDK_ROOT if ANDROID_HOME not found
35+
if 'ANDROID_HOME' not in os.environ or not os.path.exists(os.environ.get('ANDROID_HOME', '')):
36+
try:
37+
android_sdk_root_reg, _ = winreg.QueryValueEx(key, "ANDROID_SDK_ROOT")
38+
if android_sdk_root_reg:
39+
# Expand environment variables before checking if path exists
40+
android_sdk_root_expanded = os.path.expandvars(android_sdk_root_reg)
41+
if os.path.exists(android_sdk_root_expanded):
42+
os.environ['ANDROID_SDK_ROOT'] = android_sdk_root_expanded
43+
# Update PATH with platform-tools (where ADB is located)
44+
platform_tools = os.path.join(android_sdk_root_expanded, "platform-tools")
45+
current_path = os.environ.get('PATH', '')
46+
if platform_tools not in current_path:
47+
os.environ['PATH'] = f"{platform_tools};{current_path}"
48+
print(f"[installer][android-adb] Refreshed ANDROID_SDK_ROOT from registry: {android_sdk_root_expanded}")
49+
except FileNotFoundError:
50+
pass
51+
except Exception as e:
52+
print(f"[installer][android-adb] Failed to refresh from registry: {e}")
53+
54+
try:
55+
loop = asyncio.get_event_loop()
56+
result = await loop.run_in_executor(
57+
None,
58+
lambda: subprocess.run(
59+
["adb", "version"],
60+
capture_output=True,
61+
text=True,
62+
check=False
63+
)
64+
)
65+
66+
# If command succeeds (returncode = 0), ADB is installed
67+
if result.returncode == 0:
68+
version_output = (result.stdout or result.stderr).strip()
69+
print(f"[installer][android-adb] Already installed")
70+
await send_response({
71+
"action": "status",
72+
"data": {
73+
"category": "Android",
74+
"name": "ADB",
75+
"status": "installed",
76+
"comment": f"ADB is installed (version: {version_output.split()[0] if version_output else 'unknown'})",
77+
}
78+
})
79+
return True
80+
else:
81+
print("[installer][android-adb] Not installed")
82+
await send_response({
83+
"action": "status",
84+
"data": {
85+
"category": "Android",
86+
"name": "ADB",
87+
"status": "not installed",
88+
"comment": "Install ADB to use it.",
89+
}
90+
})
91+
return False
92+
except Exception as e:
93+
print(f"[installer][android-adb] Error checking status: {e}")
94+
await send_response({
95+
"action": "status",
96+
"data": {
97+
"category": "Android",
98+
"name": "ADB",
99+
"status": "not installed",
100+
"comment": "Unable to check ADB status.",
101+
}
102+
})
103+
return False
104+
105+
3106

4107

5108
async def install():
6-
print("[adb] Installing...")
109+
"""Install ADB - checks if already installed, otherwise prompts to install Android SDK."""
110+
print("[installer][android-adb] Installing...")
111+
112+
# Check if ADB is already installed
113+
if await check_status():
114+
print("[installer][android-adb] ADB is already installed")
115+
return
116+
117+
# ADB is not installed, send response to install Android SDK
118+
print("[installer][android-adb] ADB is not installed. Install Android SDK to get ADB.")
119+
await send_response({
120+
"action": "status",
121+
"data": {
122+
"category": "Android",
123+
"name": "ADB",
124+
"status": "not installed",
125+
"comment": "Install the Android SDK, it will automatically install ADB.",
126+
}
127+
})
128+
129+
130+
7131

0 commit comments

Comments
 (0)