From 098bc08dcddd7e67299922c6022571100081f169 Mon Sep 17 00:00:00 2001 From: Adin Date: Mon, 11 Aug 2025 22:18:08 +0530 Subject: [PATCH] new ui --- src/new_core.py | 317 +++++++++++++++++++++--------------------------- test/logger.py | 197 ++++++++++++++++++++---------- 2 files changed, 273 insertions(+), 241 deletions(-) diff --git a/src/new_core.py b/src/new_core.py index 61f4572..1ab3a3d 100755 --- a/src/new_core.py +++ b/src/new_core.py @@ -1,186 +1,145 @@ -from PyQt5 import QtCore, QtGui, QtWidgets +import sys +import os +from datetime import datetime from PyQt5.QtWidgets import ( - QApplication, QMainWindow, QWidget, QPushButton, QLabel, - QVBoxLayout, QHBoxLayout, QStackedWidget, QLineEdit, QTextEdit, - QFrame, QScrollArea,QComboBox,QRadioButton,QFileDialog,QMessageBox,QCheckBox + QApplication, QWidget, QLabel, QLineEdit, QPushButton, + QVBoxLayout, QHBoxLayout, QFileDialog, QComboBox, QRadioButton, QButtonGroup ) -from PyQt5.QtGui import QIcon,QFont,QPixmap,QMovie -from PyQt5.QtCore import Qt -import json -from PyQt5.QtCore import pyqtSignal -import new_ui -from styles import * -import subprocess -import os -from TTS_main import Test_begin -class Main_utils_page(QWidget): +from PyQt5.QtGui import QIcon + + +class IPATestUI(QWidget): def __init__(self): super().__init__() - self.sig_use = pyqtSignal() - self.page = self.main_page() - - def main_page(self): - page = self.create_card() - main_layout = QHBoxLayout() - main_layout.setAlignment(Qt.AlignCenter) - main_layout.addWidget(page) - page.setLayout(main_layout) - return page - - def create_card(self): - card = QWidget() - card.setStyleSheet("background-color: #272757; border-radius: 12px; padding: 2px;") - vbox = QVBoxLayout() - vbox.setAlignment(Qt.AlignTop) - vbox.setSpacing(15) - - label = QLabel("Start A Task or Schedule One") - label.setStyleSheet(my_style) - label.setAlignment(Qt.AlignCenter) - vbox.addWidget(label) - # ---------- IP Address Input ---------- - ip_path_edit = QLineEdit() - ip_path_edit.setPlaceholderText("IP Address") - ip_path_edit.setStyleSheet(my_style) - ip_path_edit.setText('169.254.80.') - vbox.addWidget(ip_path_edit) - - # ---------- Excel File Input ---------- - exe_path_edit = QLineEdit() - exe_path_edit.setPlaceholderText("Path to Excel") - exe_path_edit.setStyleSheet(my_style) - browse_btn = QPushButton("Browse") - browse_btn.setStyleSheet(my_style) - browse_btn.setFixedSize(100,40) - browse_btn.clicked.connect(lambda: exe_path_edit.setText( - QFileDialog.getOpenFileName(None, "Select Excel", "", "Excel Files (*.xlsx)")[0] - )) - - exe_hbox = QHBoxLayout() - exe_hbox.addWidget(exe_path_edit) - exe_hbox.addWidget(browse_btn) - vbox.addLayout(exe_hbox) - - # ---------- Log Folder Input ---------- - log_path_edit = QLineEdit() - log_path_edit.setPlaceholderText("Path to Log Folder") - log_path_edit.setStyleSheet(my_style) - log_browse_btn = QPushButton("Browse") - log_browse_btn.setStyleSheet(my_style) - log_browse_btn.setFixedSize(100,40) - log_browse_btn.clicked.connect(lambda: log_path_edit.setText( - QFileDialog.getExistingDirectory(self, 'Select Log Folder') - )) - - log_hbox = QHBoxLayout() - log_hbox.addWidget(log_path_edit) - log_hbox.addWidget(log_browse_btn) - vbox.addLayout(log_hbox) - - # ---------- DLP Project File ---------- - fp_path_edit = QLineEdit() - fp_path_edit.setPlaceholderText("Project file for DLT ECU Conf") - fp_path_edit.setStyleSheet(my_style) - fp_browse_btn = QPushButton("Browse") - fp_browse_btn.setStyleSheet(my_style) - fp_browse_btn.setFixedSize(100,40) - fp_browse_btn.clicked.connect(lambda: fp_path_edit.setText( - QFileDialog.getOpenFileName(None, "Select DLP File", "", "DLP Files (*.DLP)")[0] - )) - - fp_hbox = QHBoxLayout() - fp_hbox.addWidget(fp_path_edit) - fp_hbox.addWidget(fp_browse_btn) - vbox.addLayout(fp_hbox) - - # ---------- Time Input ---------- - time_input = QLineEdit() - time_input.setStyleSheet(my_style) - time_input.setPlaceholderText("Schedule Time (HH:MM, e.g., 14:30) optional IN DEVLOPMENT") - vbox.addWidget(time_input) - - # ---------- Buttons ---------- - btn_hbox = QHBoxLayout() - - test_btn = QPushButton("Start Test") - test_btn.setStyleSheet(my_style) - test_btn.setFixedSize(100,60) - test_btn.clicked.connect(lambda: Test_begin( - mcu_ip=ip_path_edit.text(), - input_excel=exe_path_edit.text(), - directory=log_path_edit.text(), - dlp_file=fp_path_edit.text(), - load=Give_load.isChecked(), - stack=tech_stack.currentText() - )) - - schedule_btn = QPushButton("Schedule") - schedule_btn.setStyleSheet(my_style) - schedule_btn.setFixedSize(100,60) - schedule_btn.clicked.connect(lambda: self.create_and_schedule_task( - exe_path_edit.text(), - "MyApp_Task", - time_input.text() - )) - checkbox_layout = QVBoxLayout() - checkbox_label = QLabel("Give load to system?") - checkbox_label.setStyleSheet(my_style) - Give_load = QRadioButton("Yes (ACA ONLY)") - Give_no_load = QRadioButton("No") - Give_load.setStyleSheet("color: white;") - Give_no_load.setStyleSheet("color: white;") - checkbox_layout.addWidget(checkbox_label) - checkbox_layout.addWidget(Give_load) - checkbox_layout.addWidget(Give_no_load) - tech_stack = QComboBox() - tech_stack.addItem("BCA") - tech_stack.addItem("Cerance") - tech_stack.setStyleSheet(combo_sheet) - checkbox_layout.addWidget(tech_stack) - vbox.addLayout(checkbox_layout) - btn_hbox.addWidget(test_btn) - btn_hbox.addWidget(schedule_btn) - vbox.addLayout(btn_hbox) - # ---------- Final Card Layout ---------- - card.setLayout(vbox) - return card - - def printer(self): - print("god") - print(self.time_input.text()) - print(self.exe_input.text()) - - def create_and_schedule_task(self, exe_path, task_name, time_str): - print(exe_path) - print(task_name) - print(time_str) - cwd = os.getcwd()+'/bats' - #we Create .bat file (i dont know how much safe is this one) - os.makedirs(cwd, exist_ok=True) # Create the directory if it doesn't exist - bat_path = os.path.join(cwd, f"{task_name}.bat") - # bat_path = os.path.join(cwd , f"{task_name}.bat") - with open(bat_path, 'w') as f: - f.write(f'start "" "{exe_path}"\n') - - # Schedule task using schtasks , like running a command in linux (can bring improvements) - hour, minute = time_str.split(":") - # https://learn.microsoft.com/en-us/windows/win32/taskschd/schtasks for your reference - # this is definetley gonna break the system - command = [ - "schtasks", - "/Create", - "/SC", "DAILY", - "/TN", task_name, - "/TR", f'"{bat_path}"', - "/ST", f"{hour}:{minute}", - "/F" - ] - - try: - subprocess.run(command, check=True) - QMessageBox.information(self, "Scheduled", f"Task '{task_name}' scheduled at {time_str}") - except subprocess.CalledProcessError as e: - QMessageBox.critical(self, "Error", f"Failed to schedule task:\n{str(e)}") + self.setWindowTitle("IPA Test Automation Runner") + self.setGeometry(200, 200, 520, 380) + + self.ip = "" + self.excel_file = "" + self.config_file = "" + self.tech = "BCA" + self.system_load = False + self.iterations = 1 + + self.timenow = datetime.now() + self.rundirectoryname = "IPA_Testrun_" + self.timenow.strftime("%d_%m_%H_%M") + self.rundirectory = "" + + self.initUI() + + def initUI(self): + layout = QVBoxLayout() + layout.setSpacing(8) + + # IP Address + ip_label = QLabel("IP Address:") + self.ip_entry = QLineEdit() + layout.addWidget(ip_label) + layout.addWidget(self.ip_entry) + + # Excel File + excel_label = QLabel("Excel File:") + excel_layout = QHBoxLayout() + self.excel_entry = QLineEdit() + excel_button = QPushButton("Browse") + excel_button.clicked.connect(self.browse_excel) + excel_layout.addWidget(self.excel_entry) + excel_layout.addWidget(excel_button) + layout.addWidget(excel_label) + layout.addLayout(excel_layout) + + # Config File + config_label = QLabel("Configuration File:") + config_layout = QHBoxLayout() + self.config_entry = QLineEdit() + config_button = QPushButton("Browse") + config_button.clicked.connect(self.browse_config) + config_layout.addWidget(self.config_entry) + config_layout.addWidget(config_button) + layout.addWidget(config_label) + layout.addLayout(config_layout) + + # Tech Stack dropdown + tech_label = QLabel("Tech Stack:") + self.tech_combo = QComboBox() + self.tech_combo.addItems(["BCA", "Cerence"]) + tech_layout = QHBoxLayout() + tech_layout.addWidget(tech_label) + tech_layout.addWidget(self.tech_combo) + layout.addLayout(tech_layout) + + # System Load radio + sysload_label = QLabel("Give System Load?") + sysload_layout = QHBoxLayout() + self.radio_yes = QRadioButton("Yes") + self.radio_no = QRadioButton("No") + self.radio_no.setChecked(True) + sysload_group = QButtonGroup(self) + sysload_group.addButton(self.radio_yes) + sysload_group.addButton(self.radio_no) + sysload_layout.addWidget(self.radio_yes) + sysload_layout.addWidget(self.radio_no) + layout.addWidget(sysload_label) + layout.addLayout(sysload_layout) + + # Iterations dropdown + iter_layout = QHBoxLayout() + iter_label = QLabel("Iteration Count:") + self.iter_combo = QComboBox() + self.iter_combo.addItems([str(i) for i in range(1, 6)]) + iter_layout.addWidget(iter_label) + iter_layout.addWidget(self.iter_combo) + layout.addLayout(iter_layout) + + # Start Button + start_button = QPushButton("Start Test") + start_button.clicked.connect(self.start_test) + layout.addWidget(start_button) + + # Status labels + self.status_total = QLabel("Total / Played: 0 / 0") + self.status_current = QLabel("Current Utterance: None") + layout.addWidget(self.status_total) + layout.addWidget(self.status_current) + + self.setLayout(layout) + + def browse_excel(self): + file_name, _ = QFileDialog.getOpenFileName(self, "Select Excel File", "", "Excel Files (*.xlsx *.xls)") + if file_name: + self.excel_entry.setText(file_name) + self.excel_file = file_name + + def browse_config(self): + file_name, _ = QFileDialog.getOpenFileName(self, "Select Configuration File", "", "All Files (*)") + if file_name: + self.config_entry.setText(file_name) + self.config_file = file_name + + def update_status(self, total_played_text=None, current_utterance_text=None, error=False): + if total_played_text is not None: + self.status_total.setText(total_played_text) + if current_utterance_text is not None: + self.status_current.setText(current_utterance_text) + + def start_test(self): + self.ip = self.ip_entry.text().strip() + self.excel_file = self.excel_entry.text().strip() + self.config_file = self.config_entry.text().strip() + self.tech = self.tech_combo.currentText() + self.system_load = self.radio_yes.isChecked() + self.iterations = int(self.iter_combo.currentText()) + print(f"IP: {self.ip}") + print(f"Excel: {self.excel_file}") + print(f"Config: {self.config_file}") + print(f"Tech Stack: {self.tech}") + print(f"System Load: {self.system_load}") + print(f"Iterations: {self.iterations}") +if __name__ == "__main__": + app = QApplication(sys.argv) + win = IPATestUI() + win.show() + sys.exit(app.exec_()) diff --git a/test/logger.py b/test/logger.py index 959ab41..4a93ceb 100644 --- a/test/logger.py +++ b/test/logger.py @@ -1,67 +1,140 @@ -import subprocess +import sys import os -import time +from PyQt5.QtWidgets import ( + QApplication, QWidget, QLabel, QLineEdit, QPushButton, + QVBoxLayout, QHBoxLayout, QFileDialog, QComboBox, QRadioButton, QButtonGroup +) +from PyQt5.QtGui import QIcon from datetime import datetime -# Configuration -device_id = 'J7S8WCZTROEQ8L9D' # Replace with your device ID or IP -log_file = "adb_logs.log" # Output log file name -duration = 3 # Duration in seconds - -def collect_logs(): - try: - print(f"Starting ADB log collection for {device_id} (duration: {duration} seconds)") - - # Get current timestamp for the log file header - timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S") - - # Open log file with proper encoding - with open(log_file, "w", encoding='ISO-8859-1') as file: - file.write(f"ADB Log Collection - Device: {device_id} - Started at {timestamp}\n") - file.write("="*60 + "\n\n") - - # Start the ADB logcat process - process = subprocess.Popen( - ["adb", "-s", device_id, "logcat"], - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - universal_newlines=True, - bufsize=1, - encoding='ISO-8859-1' - ) - - # Record start time - start_time = time.time() - - try: - # Read lines for the specified duration - while time.time() - start_time < duration: - line = process.stdout.readline() - if line: - file.write(line) - file.flush() - else: - break # Exit if process ended - - except KeyboardInterrupt: - print("\nLog collection interrupted by user") - - finally: - # Clean up the process - process.terminate() - try: - process.wait(timeout=1) - except subprocess.TimeoutExpired: - process.kill() - - # Add footer information - file.write(f"\n\nLog collection completed after {duration} seconds") - print(f"\nLogs saved to {os.path.abspath(log_file)}") - - except Exception as e: - print(f"Error occurred: {str(e)}") - if 'process' in locals(): - process.terminate() + +class IPATestUI(QWidget): + def __init__(self): + super().__init__() + self.setWindowTitle("IPA Test Automation Runner") + self.setWindowIcon(QIcon(":/icons/IAV_Logo.ico")) + self.setGeometry(200, 200, 500, 350) + + # Store values + self.ip = "" + self.excel_file = "" + self.config_file = "" + self.system_load = False + self.iterations = 1 + + # Timestamped run directory + self.timenow = datetime.now() + self.rundirectoryname = "IPA_Testrun_" + self.timenow.strftime("%d_%m_%H_%M") + self.rundirectory = "" + + self.initUI() + + def initUI(self): + layout = QVBoxLayout() + + # IP Address + ip_label = QLabel("IP Address:") + self.ip_entry = QLineEdit() + layout.addWidget(ip_label) + layout.addWidget(self.ip_entry) + + # Excel File + excel_label = QLabel("Excel File:") + excel_layout = QHBoxLayout() + self.excel_entry = QLineEdit() + excel_button = QPushButton("Browse") + excel_button.clicked.connect(self.browse_excel) + excel_layout.addWidget(self.excel_entry) + excel_layout.addWidget(excel_button) + layout.addWidget(excel_label) + layout.addLayout(excel_layout) + + # Config File + config_label = QLabel("Configuration File:") + config_layout = QHBoxLayout() + self.config_entry = QLineEdit() + config_button = QPushButton("Browse") + config_button.clicked.connect(self.browse_config) + config_layout.addWidget(self.config_entry) + config_layout.addWidget(config_button) + layout.addWidget(config_label) + layout.addLayout(config_layout) + + # System Load (Yes/No) + sysload_label = QLabel("Give System Load?") + sysload_layout = QHBoxLayout() + self.radio_yes = QRadioButton("Yes") + self.radio_no = QRadioButton("No") + self.radio_no.setChecked(True) + sysload_group = QButtonGroup(self) + sysload_group.addButton(self.radio_yes) + sysload_group.addButton(self.radio_no) + sysload_layout.addWidget(self.radio_yes) + sysload_layout.addWidget(self.radio_no) + layout.addWidget(sysload_label) + layout.addLayout(sysload_layout) + + # Iteration Count + iter_layout = QHBoxLayout() + iter_label = QLabel("Iteration Count:") + self.iter_combo = QComboBox() + self.iter_combo.addItems([str(i) for i in range(1, 6)]) + iter_layout.addWidget(iter_label) + iter_layout.addWidget(self.iter_combo) + layout.addLayout(iter_layout) + + # Start Button + start_button = QPushButton("Start Test") + start_button.clicked.connect(self.start_test) + layout.addWidget(start_button) + + # Status labels + self.status_total = QLabel("Total / Played: 0 / 0") + self.status_current = QLabel("Current Utterance: None") + layout.addWidget(self.status_total) + layout.addWidget(self.status_current) + + self.setLayout(layout) + + def browse_excel(self): + file_name, _ = QFileDialog.getOpenFileName(self, "Select Excel File", "", "Excel Files (*.xlsx *.xls)") + if file_name: + self.excel_entry.setText(file_name) + self.excel_file = file_name + + def browse_config(self): + file_name, _ = QFileDialog.getOpenFileName(self, "Select Configuration File", "", "Config Files (*.txt *.cfg *.ini);;All Files (*)") + if file_name: + self.config_entry.setText(file_name) + self.config_file = file_name + + def start_test(self): + self.ip = self.ip_entry.text() + self.system_load = self.radio_yes.isChecked() + self.iterations = int(self.iter_combo.currentText()) + + # Check inputs + if not self.ip or not self.excel_file or not self.config_file: + self.update_status("Please provide all required inputs.", error=True) + return + + # Create run directory + self.rundirectory = os.path.join(os.getcwd(), self.rundirectoryname) + os.makedirs(self.rundirectory, exist_ok=True) + + self.update_status(f"Starting IPA Test on {self.ip}...", error=False) + + # TODO: Replace with your actual test runner logic + print(f"Running with: IP={self.ip}, Excel={self.excel_file}, Config={self.config_file}, " + f"SystemLoad={self.system_load}, Iterations={self.iterations}") + + def update_status(self, message, error=False): + color = "red" if error else "green" + self.status_total.setText(f'{message}') + if __name__ == "__main__": - collect_logs() + app = QApplication(sys.argv) + win = IPATestUI() + win.show() + sys.exit(app.exec_())