Skip to content

Commit 9104760

Browse files
committed
Fix: settings file was generated later than expected
Other node modules and codes depend on the settings to be available at import time. So this ended up causing weird issues that caused test case execution results not being stored properly.
1 parent db7acfe commit 9104760

File tree

1 file changed

+54
-43
lines changed

1 file changed

+54
-43
lines changed

node_cli.py

Lines changed: 54 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@
3131
from urllib3.exceptions import InsecureRequestWarning
3232
import uvicorn
3333

34-
print(f"Python {platform.python_version()} ({platform.architecture()[0]}) @ {sys.executable}")
34+
print(
35+
f"Python {platform.python_version()} ({platform.architecture()[0]}) @ {sys.executable}"
36+
)
3537
print(f"Current file path: {os.path.abspath(__file__)}")
3638

39+
3740
def adjust_python_path():
3841
"""Adjusts the Python path to include the Framework directory."""
3942
root_dir = Path.cwd()
@@ -48,12 +51,46 @@ def adjust_python_path():
4851
# Move to Framework directory and add parent to path for module imports
4952
os.chdir(framework_dir)
5053

54+
55+
def create_config_file():
56+
settings_conf_path = Path.cwd() / "settings.conf"
57+
if settings_conf_path.exists():
58+
return
59+
60+
today = date.today().strftime("%Y-%m-%d")
61+
62+
config = ConfigObj()
63+
config["Authentication"] = {"username": "", "api-key": "", "server_address": ""}
64+
config["Advanced Options"] = {
65+
"module_update_interval": 30,
66+
"log_delete_interval": 7,
67+
"last_module_update_date": today,
68+
"last_log_delete_date": today,
69+
"element_wait": 10,
70+
"available_to_all_project": False,
71+
"_file": "temp_config.ini",
72+
"_file_upload_path": "TestExecutionLog",
73+
"stop_live_log": False,
74+
}
75+
config["Inspector"] = {
76+
"Window": "",
77+
"No_of_level_to_skip": 0,
78+
"ai_plugin": True,
79+
}
80+
config["server"] = {"port": 0}
81+
config.filename = str(settings_conf_path)
82+
config.write()
83+
print(f"Created settings.conf at {settings_conf_path}")
84+
85+
5186
adjust_python_path()
87+
create_config_file()
88+
5289

5390
from Framework.module_installer import ( # noqa: E402
5491
check_min_python_version,
55-
install_missing_modules,
5692
update_outdated_modules,
93+
# install_missing_modules,
5794
)
5895

5996
from Framework.deploy_handler import ( # noqa: E402
@@ -65,39 +102,10 @@ def adjust_python_path():
65102
from Framework.node_server_state import STATE # noqa: E402
66103
from server import main as node_server # noqa: E402
67104

68-
settings_conf_path = str(Path(__file__).parent / "Framework" / "settings.conf")
69-
def create_config_file():
70-
if not os.path.exists(settings_conf_path):
71-
config = ConfigObj()
72-
config["Authentication"] = {
73-
"username": "",
74-
"api-key": "",
75-
"server_address": ""
76-
}
77-
config["Advanced Options"] = {
78-
"module_update_interval": 30,
79-
"log_delete_interval": 7,
80-
"last_module_update_date": "2025-02-21",
81-
"last_log_delete_date": "2023-09-19",
82-
"element_wait": 10,
83-
"available_to_all_project": False,
84-
"_file": "temp_config.ini",
85-
"_file_upload_path": "TestExecutionLog",
86-
"stop_live_log": False
87-
}
88-
config["Inspector"] = {
89-
"Window": "",
90-
"No_of_level_to_skip": 0,
91-
"ai_plugin": True
92-
}
93-
config["server"] = {
94-
"port": 0
95-
}
96-
config.filename = settings_conf_path
97-
config.write()
98-
print(f"Created settings.conf at {settings_conf_path}")
99105

100106
def start_server():
107+
settings_conf_path = Path.cwd() / "settings.conf"
108+
101109
def is_port_in_use(port):
102110
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
103111
return s.connect_ex(("127.0.0.1", port)) == 0
@@ -109,7 +117,7 @@ def run():
109117
while is_port_in_use(node_server_port) and tries < 99:
110118
node_server_port += 1
111119
tries += 1
112-
config = ConfigObj(settings_conf_path)
120+
config = ConfigObj(str(settings_conf_path))
113121
config["server"]["port"] = node_server_port
114122
config.write()
115123
uvicorn.run(
@@ -118,7 +126,7 @@ def run():
118126
port=node_server_port,
119127
log_level="warning",
120128
)
121-
129+
122130
except Exception as e:
123131
print(f"[WARN] Failed to launch node-server: {str(e)}")
124132

@@ -165,7 +173,6 @@ def monkeypatch_fromisoformat():
165173

166174

167175
def main():
168-
169176
# Load environment variables from .env file
170177
load_dotenv()
171178

@@ -181,7 +188,6 @@ def main():
181188

182189
kill_old_process(Path.cwd().parent / "pid.txt")
183190
check_min_python_version(min_python_version="3.11", show_warning=True)
184-
create_config_file()
185191
update_outdated_modules()
186192
monkeypatch_fromisoformat()
187193
start_server()
@@ -1059,9 +1065,11 @@ def Bypass():
10591065

10601066
STATE.reconnect_with_credentials = None
10611067

1062-
server_name = ConfigModule.get_config_value(
1063-
AUTHENTICATION_TAG, "server_address"
1064-
).strip('""').strip()
1068+
server_name = (
1069+
ConfigModule.get_config_value(AUTHENTICATION_TAG, "server_address")
1070+
.strip('""')
1071+
.strip()
1072+
)
10651073
api = (
10661074
ConfigModule.get_config_value(AUTHENTICATION_TAG, "api-key")
10671075
.strip('"')
@@ -1070,7 +1078,10 @@ def Bypass():
10701078

10711079
if len(server_name) == 0 and len(api) == 0:
10721080
if print_login_information:
1073-
console.print("\n" + ":red_circle: " + "Zeuz Node is disconnected.", style="bold red")
1081+
console.print(
1082+
"\n" + ":red_circle: " + "Zeuz Node is disconnected.",
1083+
style="bold red",
1084+
)
10741085
console.print("Please log in to ZeuZ server and connect.")
10751086

10761087
print_login_information = False
@@ -1087,8 +1098,8 @@ def Bypass():
10871098

10881099
if RUN_ONCE:
10891100
console.print(
1090-
":yellow_circle: " +
1091-
"Zeuz Node is going offline after running one session, since `--once` or `-o` flag is specified.",
1101+
":yellow_circle: "
1102+
+ "Zeuz Node is going offline after running one session, since `--once` or `-o` flag is specified.",
10921103
style="bold cyan",
10931104
)
10941105
os._exit(0)

0 commit comments

Comments
 (0)