From d602fa9960c451065fcfd001d5c2cbe95954d113 Mon Sep 17 00:00:00 2001 From: alya Date: Mon, 2 Sep 2024 17:21:38 +0300 Subject: [PATCH] remove all logic handling output redirection since its no longer needed --- managers/process_manager.py | 1 - slips/main.py | 4 +--- slips_files/core/helpers/checker.py | 34 ----------------------------- slips_files/core/output.py | 23 ------------------- 4 files changed, 1 insertion(+), 61 deletions(-) diff --git a/managers/process_manager.py b/managers/process_manager.py index ec215442d..74c5f344c 100644 --- a/managers/process_manager.py +++ b/managers/process_manager.py @@ -112,7 +112,6 @@ def is_pbar_supported(self) -> bool: def start_output_process(self, current_stdout, stderr, slips_logfile): output_process = Output( - stdout=current_stdout, stderr=stderr, slips_logfile=slips_logfile, verbose=self.main.args.verbose or 0, diff --git a/slips/main.py b/slips/main.py index 0e6a21fa5..77090968f 100644 --- a/slips/main.py +++ b/slips/main.py @@ -618,10 +618,8 @@ def start(self): self.print_version() print("https://stratosphereips.org") print("-" * 27) - self.setup_print_levels() - - self.stdout: str = self.checker.check_stdout_redirection() + self.stdout = "" stderr: str = self.get_slips_error_file() slips_logfile: str = self.get_slips_logfile() # if stdout is redirected to a file, diff --git a/slips_files/core/helpers/checker.py b/slips_files/core/helpers/checker.py index 12aafc582..1f662d7a1 100644 --- a/slips_files/core/helpers/checker.py +++ b/slips_files/core/helpers/checker.py @@ -1,5 +1,4 @@ import os -import subprocess import sys import psutil @@ -201,37 +200,4 @@ def input_module_exists(self, module): f"Stopping Slips." ) return False - return True - - def check_stdout_redirection(self) -> str: - """ - Determine if the stdout is redirected to a file - return the current_stdout - current_stdout will be '' if it's not redirected to a file - """ - print("@@@@@@@@@@@@@@@@ check_output_redirection is called!") - # lsof will provide a list of all open fds belonging to slips - # -a: Combines the conditions. - # -d 1,2: Filters by file descriptors 1 (stdout) and 2 (stderr). - command = f"lsof -p {self.main.pid} -a -d 1" - result = subprocess.run(command.split(), capture_output=True) - # Get command output - output = result.stdout.decode("utf-8") - # if stdout is being redirected we'll find '1w' in one of the lines - # 1 means stdout, w means write mode - # by default, stdout is not redirected - current_stdout = "" - for line in output.splitlines(): - # /dev/pts means we're running in a terminal, if redirection is - # used, the files name will be there instead - # Command is the header line - if "/dev/pts/" not in line and "COMMAND" not in line: - # stdout is redirected, get the file - current_stdout: str = line.split(" ")[-1] - break - print( - f"@@@@@@@@@@@@@@@@ check_stdout_redirection: current_stdout" - f" {current_stdout}" - ) - return current_stdout diff --git a/slips_files/core/output.py b/slips_files/core/output.py index 9f55ffedd..a362443b4 100644 --- a/slips_files/core/output.py +++ b/slips_files/core/output.py @@ -17,7 +17,6 @@ from multiprocessing.connection import Connection from multiprocessing import Event import sys -import io from pathlib import Path from datetime import datetime import os @@ -46,7 +45,6 @@ def __init__( self, verbose=1, debug=0, - stdout="", stderr="output/errors.log", slips_logfile="output/slips.log", input_type=False, @@ -85,10 +83,6 @@ def __init__( utils.change_logfiles_ownership( self.slips_logfile, self.UID, self.GID ) - self.stdout = stdout - if stdout != "": - self.change_stdout() - if self.verbose > 2: print(f"Verbosity: {self.verbose}. Debugging: {self.debug}") @@ -149,23 +143,6 @@ def log_line(self, msg: dict): slips_logfile.write(f"{date_time} [{sender}] {msg}\n") self.slips_logfile_lock.release() - def change_stdout(self): - """ - to be able to print the stats to the output file - """ - # io.TextIOWrapper creates a file object of this file - # Pass 0 to open() to switch output buffering off - # (only allowed in binary mode) - # write_through= True, to flush the buffer to disk, from there the - # file can read it. - # without it, the file writer keeps the information in a local buffer - # that's not accessible to the file. - stdout = io.TextIOWrapper( - open(self.stdout, "wb", 0), write_through=True - ) - sys.stdout = stdout - return stdout - def print(self, sender: str, txt: str, end="\n"): """ prints the given txt whether using tqdm or using print()