From 78434e0b230b2f16e9130e8bf169f10f289c0004 Mon Sep 17 00:00:00 2001 From: sBubshait Date: Tue, 5 Aug 2025 16:17:43 +0300 Subject: [PATCH] feat: redirect the output to the client terminal --- activationDrill/drillClient.py | 33 ++++++++++++++++++++++++++------- 1 file changed, 26 insertions(+), 7 deletions(-) diff --git a/activationDrill/drillClient.py b/activationDrill/drillClient.py index 6496ad6..487b8f1 100644 --- a/activationDrill/drillClient.py +++ b/activationDrill/drillClient.py @@ -46,18 +46,39 @@ class ActivationDrillClient: """ print(banner) - def run_command(self, cmd: str, capture_output: bool = True, as_user: str = None) -> Tuple[bool, str]: + def run_command(self, cmd: str, capture_output: bool = True, as_user: str = None, show_output: bool = False) -> Tuple[bool, str]: """Execute shell command and return success status and output""" try: if as_user: cmd = f"su - {as_user} -c '{cmd}'" - if capture_output: + if capture_output and not show_output: result = subprocess.run( cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, check=False ) return result.returncode == 0, result.stdout + result.stderr + elif show_output: + # Real-time output display + print(f"{Colors.DIM} Command output:{Colors.ENDC}") + process = subprocess.Popen( + cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, + universal_newlines=True, bufsize=1 + ) + + output_lines = [] + while True: + line = process.stdout.readline() + if not line and process.poll() is not None: + break + if line: + line = line.rstrip() + print(f"{Colors.DIM} {line}{Colors.ENDC}") + output_lines.append(line) + + return_code = process.poll() + print() # Add blank line after command output + return return_code == 0, '\n'.join(output_lines) else: result = subprocess.run(cmd, shell=True, check=False) return result.returncode == 0, "" @@ -157,7 +178,7 @@ class ActivationDrillClient: def check_hana_status(self) -> Tuple[bool, str]: """Check HANA database status""" - success, output = self.run_command("HDB info", as_user="prcadm") + success, output = self.run_command("HDB info", as_user="prcadm", show_output=True) if success and "hdbnameserver" in output.lower(): return True, "HANA is running" else: @@ -182,23 +203,21 @@ class ActivationDrillClient: print(f"\n{Colors.YELLOW}Unregistering from system replication...{Colors.ENDC}") self.show_loading("Unregistering", 4.0) - success, output = self.run_command("hdbnsutil -sr_unregister", as_user="prcadm") + success, output = self.run_command("hdbnsutil -sr_unregister", as_user="prcadm", show_output=True) if success: print(f"{Colors.GREEN}✓ Successfully unregistered from system replication{Colors.ENDC}") else: print(f"{Colors.YELLOW}⚠ Unregister command completed with warnings{Colors.ENDC}") - print(f"{Colors.DIM}{output[:200]}...{Colors.ENDC}") # Start HANA database print(f"\n{Colors.YELLOW}Starting HANA database...{Colors.ENDC}") self.show_loading("Starting database", 8.0) - success, output = self.run_command("HDB start", as_user="prcadm") + success, output = self.run_command("HDB start", as_user="prcadm", show_output=True) if success: print(f"{Colors.GREEN}✓ HANA database started successfully{Colors.ENDC}") else: print(f"{Colors.RED}✗ Failed to start HANA database{Colors.ENDC}") - print(f"{Colors.RED}{output[:300]}{Colors.ENDC}") return # Check database health