Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logger #142

Merged
merged 6 commits into from
May 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion src/models/IDE/VisualStudioCode.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import subprocess
import time

Expand All @@ -9,6 +10,10 @@
from src.utils.general import get_clipboard_text
from src.utils.general import parse_kantra_cli_command

logging.basicConfig(level=logging.DEBUG)

logger = logging.getLogger(__name__)


class VisualStudioCode(Application):
"""
Expand All @@ -27,8 +32,10 @@ def cmd_palette_exec_command(self, command: VSCodeCommandEnum):
"""
Execute commands in the command palette in vscode
"""
logger.info("Open command palette")
self.press_keys("ctrl", "shift", "p")
time.sleep(1)
logger.info(f"Execute command: {command.value}")
self.type_text(command.value)
time.sleep(1)
self.press_keys("enter")
Expand All @@ -52,6 +59,7 @@ def close_ide(self):
"""
Closes the IDE
"""
logger.info("Close IDE")
self.set_focus()
self.press_keys("ctrl", "q")

Expand All @@ -76,9 +84,12 @@ def run_simple_analysis(self, configuration_name: str):
Runs analysis after creating an analysis configuration
"""
# Wait for new configuration' to become visible
logger.info("Refresh configuration")
self.refresh_configuration()
self.cmd_palette_exec_command(VSCodeCommandEnum.RUN_ANALYSIS)
logger.info(f"Type text: [{configuration_name}]")
self.type_text(configuration_name)
logger.info("CLick enter")
self.press_keys("enter")

# todo: There's is really no need to verify if the analysis started or not, because it will eventually go to one of 3 states, analysis failed, analysis completed, or timout error
Expand All @@ -104,11 +115,14 @@ def is_analysis_complete(self, timeout=300):
while True:
output_log_lines = self.copy_terminal_output()
if output_log_lines[-1:][0] == "Analysis completed successfully":
logger.info("Analysis completed successfully")
self.update_analysis_summery()
return True, ""
elif output_log_lines[-1:][0] == "Analysis failed":
logger.info("Analysis failed")
return False, "Analysis Failed"
elif time.time() - start_time > timeout:
logger.info("Timeout analysis not complete")
return False, "Timeout analysis not complete"
time.sleep(15)

Expand All @@ -135,11 +149,15 @@ def copy_terminal_output(self):
Copy the content of the output panel to the clipboard
split into lines, and return the list
"""
logger.info("Focus output MTA console")
self.focus_terminal_output_panel()
logger.info("Copy Console output")
self.press_keys("ctrl", "a")
self.press_keys("ctrl", "c")
self.press_keys("esc")
return get_clipboard_text(True)
clipboard_text = get_clipboard_text(True)
logger.info(clipboard_text)
return clipboard_text

def clear_terminal_output_panel(self):
"""
Expand Down
Loading