From fe19000c3938d5fda8e73e46f8f905a8fc865af5 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 21 Feb 2024 22:28:37 -0300 Subject: [PATCH 01/12] Updates - new futures --- src/upd8all_updater_unstable.py | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/src/upd8all_updater_unstable.py b/src/upd8all_updater_unstable.py index 5186be5..8e3b77b 100644 --- a/src/upd8all_updater_unstable.py +++ b/src/upd8all_updater_unstable.py @@ -27,24 +27,29 @@ def execute_command_with_sudo(command, sudo_password): command, shell=True, stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - universal_newlines=True + stdout=slave, + stderr=slave, + close_fds=True ) # Send sudo password - sudo_prompt = proc.communicate(f"{sudo_password}\n")[1] - if "Sorry" in sudo_prompt: # If "Sorry" in sudo prompt, password was incorrect - print("Incorrect sudo password. Exiting.") - sys.exit(1) + os.write(master, (sudo_password + "\n").encode()) + os.close(master) # Read output - stdout, stderr = proc.communicate() - print(stdout) - print(stderr) + while True: + r, _, _ = select.select([slave], [], []) + if r: + output = os.read(slave, 1024).decode().strip() + if not output: + break + print(output) + + proc.wait() else: os.system(command) + # Function to update Pacman packages def update_pacman(sudo_password): print("Updating Pacman packages...") @@ -134,6 +139,9 @@ def main(): timer_thread = threading.Timer(60, timeout_warning) timer_thread.start() + # Inform the user about program termination after 1 minute of inactivity + print("\nNote: If no further input is provided within 1 minute, the program will terminate.\n") + # Request package name and package manager to check its version print("Select the package manager to check the version:") print("1. Pacman") @@ -144,6 +152,7 @@ def main(): selected_option = input("Enter the option number (e.g., 1) or 'q' to quit: ").strip().lower() + # Check if the user wants to quit if selected_option == 'q': print("\nExiting the program.\n") From f8b9e9a79767ed0bb69284a2caf579e1c61c0867 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 21 Feb 2024 22:31:14 -0300 Subject: [PATCH 02/12] Updates - new futures --- src/upd8all_updater_unstable.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/upd8all_updater_unstable.py b/src/upd8all_updater_unstable.py index 8e3b77b..8d7d9c2 100644 --- a/src/upd8all_updater_unstable.py +++ b/src/upd8all_updater_unstable.py @@ -96,7 +96,7 @@ def check_package_version(package, package_manager): # Function executed in a separate thread to show a warning message if no package name is entered within 1 minute def timeout_warning(): print("\nTime's up. Program execution has ended.\n") - sys.stdout.flush() # Limpiar el buffer de salida + sys.stdout.flush() # Flush the output buffer sys.exit(0) From f709b24965851729999ab9e3708c3c7afc43a6e8 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 21 Feb 2024 22:36:01 -0300 Subject: [PATCH 03/12] Updates - new futures --- src/upd8all_updater_unstable.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/upd8all_updater_unstable.py b/src/upd8all_updater_unstable.py index 8d7d9c2..7078fa1 100644 --- a/src/upd8all_updater_unstable.py +++ b/src/upd8all_updater_unstable.py @@ -74,7 +74,6 @@ def update_brew(): print("\nUpdating packages with Homebrew...") print("-------------------------------------") command = "brew update && brew upgrade" - os.system(command) print("\n-----------------------------------\n") @@ -96,7 +95,6 @@ def check_package_version(package, package_manager): # Function executed in a separate thread to show a warning message if no package name is entered within 1 minute def timeout_warning(): print("\nTime's up. Program execution has ended.\n") - sys.stdout.flush() # Flush the output buffer sys.exit(0) @@ -168,7 +166,6 @@ def main(): package_manager = "brew" else: print("\nInvalid option (Or, you didn't choose any option above). Exiting the program.\n") - sys.stdout.flush() # Flush the output buffer sys.exit(1) # Cancel timer if the user provides a package name From 2b8a444b51c145639c0ffb8124878f9942b22512 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 21 Feb 2024 22:38:05 -0300 Subject: [PATCH 04/12] Updates - new futures --- src/upd8all_updater_unstable.py | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/src/upd8all_updater_unstable.py b/src/upd8all_updater_unstable.py index 7078fa1..c9f4a7c 100644 --- a/src/upd8all_updater_unstable.py +++ b/src/upd8all_updater_unstable.py @@ -22,30 +22,25 @@ def print_welcome_message(): # Function to execute a command with sudo as needed def execute_command_with_sudo(command, sudo_password): if command.startswith("sudo"): - master, slave = pty.openpty() proc = subprocess.Popen( command, shell=True, stdin=subprocess.PIPE, - stdout=slave, - stderr=slave, - close_fds=True + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True ) # Send sudo password - os.write(master, (sudo_password + "\n").encode()) - os.close(master) + sudo_prompt = proc.communicate(f"{sudo_password}\n")[1] + if "Sorry" in sudo_prompt: # If "Sorry" in sudo prompt, password was incorrect + print("Incorrect sudo password. Exiting.") + sys.exit(1) # Read output - while True: - r, _, _ = select.select([slave], [], []) - if r: - output = os.read(slave, 1024).decode().strip() - if not output: - break - print(output) - - proc.wait() + stdout, stderr = proc.communicate() + print(stdout) + print(stderr) else: os.system(command) @@ -74,6 +69,7 @@ def update_brew(): print("\nUpdating packages with Homebrew...") print("-------------------------------------") command = "brew update && brew upgrade" + os.system(command) print("\n-----------------------------------\n") @@ -95,6 +91,7 @@ def check_package_version(package, package_manager): # Function executed in a separate thread to show a warning message if no package name is entered within 1 minute def timeout_warning(): print("\nTime's up. Program execution has ended.\n") + sys.stdout.flush() # Flush the output buffer sys.exit(0) @@ -166,6 +163,7 @@ def main(): package_manager = "brew" else: print("\nInvalid option (Or, you didn't choose any option above). Exiting the program.\n") + sys.stdout.flush() # Flush the output buffer sys.exit(1) # Cancel timer if the user provides a package name From b9eb63ca55c4b1ff4ab48936049bbc1f975291d2 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 21 Feb 2024 22:40:27 -0300 Subject: [PATCH 05/12] Updates - new futures --- src/upd8all_updater_unstable.py | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/src/upd8all_updater_unstable.py b/src/upd8all_updater_unstable.py index c9f4a7c..b5924f1 100644 --- a/src/upd8all_updater_unstable.py +++ b/src/upd8all_updater_unstable.py @@ -22,25 +22,30 @@ def print_welcome_message(): # Function to execute a command with sudo as needed def execute_command_with_sudo(command, sudo_password): if command.startswith("sudo"): + master, slave = pty.openpty() proc = subprocess.Popen( command, shell=True, stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - universal_newlines=True + stdout=slave, + stderr=slave, + close_fds=True ) # Send sudo password - sudo_prompt = proc.communicate(f"{sudo_password}\n")[1] - if "Sorry" in sudo_prompt: # If "Sorry" in sudo prompt, password was incorrect - print("Incorrect sudo password. Exiting.") - sys.exit(1) + os.write(master, (sudo_password + "\n").encode()) + os.close(master) # Read output - stdout, stderr = proc.communicate() - print(stdout) - print(stderr) + while True: + r, _, _ = select.select([slave], [], []) + if r: + output = os.read(slave, 1024).decode().strip() + if not output: + break + print(output) + + proc.wait() else: os.system(command) @@ -66,13 +71,12 @@ def update_yay(sudo_password): # Function to update packages with Homebrew def update_brew(): - print("\nUpdating packages with Homebrew...") + print("Updating packages with Homebrew...") print("-------------------------------------") command = "brew update && brew upgrade" - os.system(command) print("\n-----------------------------------\n") - + # Function to check the version of a package in a specific package manager def check_package_version(package, package_manager): if package_manager == "pacman": From abcd43cb8435d361601ab9a74d37af3e598cf6dc Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 21 Feb 2024 22:45:44 -0300 Subject: [PATCH 06/12] Updates - new futures --- src/upd8all_updater_unstable.py | 61 ++++++++++++--------------------- 1 file changed, 22 insertions(+), 39 deletions(-) diff --git a/src/upd8all_updater_unstable.py b/src/upd8all_updater_unstable.py index b5924f1..820dcba 100644 --- a/src/upd8all_updater_unstable.py +++ b/src/upd8all_updater_unstable.py @@ -20,45 +20,29 @@ def print_welcome_message(): """) # Function to execute a command with sudo as needed -def execute_command_with_sudo(command, sudo_password): - if command.startswith("sudo"): - master, slave = pty.openpty() - proc = subprocess.Popen( - command, - shell=True, - stdin=subprocess.PIPE, - stdout=slave, - stderr=slave, - close_fds=True - ) - - # Send sudo password - os.write(master, (sudo_password + "\n").encode()) - os.close(master) - - # Read output - while True: - r, _, _ = select.select([slave], [], []) - if r: - output = os.read(slave, 1024).decode().strip() - if not output: - break - print(output) - - proc.wait() - else: - os.system(command) - +def execute_command_with_sudo(command): + proc = subprocess.Popen( + ["sudo", "-S", *command.split()], + stdin=subprocess.PIPE, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + universal_newlines=True + ) + + # Read output + stdout, stderr = proc.communicate(input=sudo_password + '\n') + print(stdout) + print(stderr) # Function to update Pacman packages -def update_pacman(sudo_password): +def update_pacman(): print("Updating Pacman packages...") print("-------------------------------------") command = "sudo pacman -Syu --noconfirm" - execute_command_with_sudo(command, sudo_password) + execute_command_with_sudo(command) # Function to update AUR packages with Yay -def update_yay(sudo_password): +def update_yay(): print("Updating AUR packages with Yay...") print("-------------------------------------") config_path = os.path.expanduser("~/.config/yay/") @@ -67,16 +51,16 @@ def update_yay(sudo_password): with open(config_file, "w") as f: json.dump({"misc": {"save": True}}, f) command = "yay -Syu --noconfirm" - execute_command_with_sudo(command, sudo_password) + execute_command_with_sudo(command) # Function to update packages with Homebrew def update_brew(): - print("Updating packages with Homebrew...") + print("\nUpdating packages with Homebrew...") print("-------------------------------------") command = "brew update && brew upgrade" os.system(command) print("\n-----------------------------------\n") - + # Function to check the version of a package in a specific package manager def check_package_version(package, package_manager): if package_manager == "pacman": @@ -98,7 +82,6 @@ def timeout_warning(): sys.stdout.flush() # Flush the output buffer sys.exit(0) - def main(): # Print welcome message print_welcome_message() @@ -118,14 +101,15 @@ def main(): has_brew = False # Request sudo password at the start of the program + global sudo_password sudo_password = getpass.getpass(prompt="Enter your sudo password: ") print() # Add a newline after entering the password # Update packages - update_pacman(sudo_password) + update_pacman() if has_yay: - update_yay(sudo_password) + update_yay() else: print("You do not have Yay installed.") @@ -151,7 +135,6 @@ def main(): selected_option = input("Enter the option number (e.g., 1) or 'q' to quit: ").strip().lower() - # Check if the user wants to quit if selected_option == 'q': print("\nExiting the program.\n") From 7bc12dce1e8cc8dea8a2aede55c364bfd9eadaad Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 21 Feb 2024 22:48:01 -0300 Subject: [PATCH 07/12] Updates - new futures --- src/upd8all_updater_unstable.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/upd8all_updater_unstable.py b/src/upd8all_updater_unstable.py index 820dcba..b45b761 100644 --- a/src/upd8all_updater_unstable.py +++ b/src/upd8all_updater_unstable.py @@ -29,7 +29,7 @@ def execute_command_with_sudo(command): universal_newlines=True ) - # Read output + # Send sudo password stdout, stderr = proc.communicate(input=sudo_password + '\n') print(stdout) print(stderr) @@ -38,7 +38,7 @@ def execute_command_with_sudo(command): def update_pacman(): print("Updating Pacman packages...") print("-------------------------------------") - command = "sudo pacman -Syu --noconfirm" + command = "pacman -Syu --noconfirm" execute_command_with_sudo(command) # Function to update AUR packages with Yay From 0b4c8dbbaf7c71ff1e0ebf25c64ea9359eda88d0 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 21 Feb 2024 22:49:59 -0300 Subject: [PATCH 08/12] Updates - new futures --- src/upd8all_updater_unstable.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/upd8all_updater_unstable.py b/src/upd8all_updater_unstable.py index b45b761..38c4ebb 100644 --- a/src/upd8all_updater_unstable.py +++ b/src/upd8all_updater_unstable.py @@ -24,15 +24,16 @@ def execute_command_with_sudo(command): proc = subprocess.Popen( ["sudo", "-S", *command.split()], stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL, universal_newlines=True ) # Send sudo password stdout, stderr = proc.communicate(input=sudo_password + '\n') - print(stdout) - print(stderr) + if proc.returncode != 0: + print(f"Error executing command with sudo: {command}") + sys.exit(1) # Function to update Pacman packages def update_pacman(): From d9e3084344af6795309720ac38da2ee50ab36227 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 21 Feb 2024 22:51:44 -0300 Subject: [PATCH 09/12] Updates - new futures --- src/upd8all_updater_unstable.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/upd8all_updater_unstable.py b/src/upd8all_updater_unstable.py index 38c4ebb..5bcad67 100644 --- a/src/upd8all_updater_unstable.py +++ b/src/upd8all_updater_unstable.py @@ -24,8 +24,8 @@ def execute_command_with_sudo(command): proc = subprocess.Popen( ["sudo", "-S", *command.split()], stdin=subprocess.PIPE, - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL, + stdout=sys.stdout, + stderr=sys.stderr, universal_newlines=True ) From 2815179501cfecc4858d09bc20afbd2886e65513 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 21 Feb 2024 22:53:26 -0300 Subject: [PATCH 10/12] Updates - new futures --- src/upd8all_updater_unstable.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/upd8all_updater_unstable.py b/src/upd8all_updater_unstable.py index 5bcad67..0c67abd 100644 --- a/src/upd8all_updater_unstable.py +++ b/src/upd8all_updater_unstable.py @@ -37,14 +37,14 @@ def execute_command_with_sudo(command): # Function to update Pacman packages def update_pacman(): - print("Updating Pacman packages...") + print("\nUpdating Pacman packages...\n") print("-------------------------------------") command = "pacman -Syu --noconfirm" execute_command_with_sudo(command) # Function to update AUR packages with Yay def update_yay(): - print("Updating AUR packages with Yay...") + print("\nUpdating AUR packages with Yay...\n") print("-------------------------------------") config_path = os.path.expanduser("~/.config/yay/") os.makedirs(config_path, exist_ok=True) From 218ea5f7c447e93213f7dc05d826d605d8d75a13 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 21 Feb 2024 22:54:31 -0300 Subject: [PATCH 11/12] Updates - new futures --- src/upd8all_updater_unstable.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/upd8all_updater_unstable.py b/src/upd8all_updater_unstable.py index 0c67abd..a3642c6 100644 --- a/src/upd8all_updater_unstable.py +++ b/src/upd8all_updater_unstable.py @@ -37,14 +37,14 @@ def execute_command_with_sudo(command): # Function to update Pacman packages def update_pacman(): - print("\nUpdating Pacman packages...\n") + print("\nUpdating Pacman packages...") print("-------------------------------------") command = "pacman -Syu --noconfirm" execute_command_with_sudo(command) # Function to update AUR packages with Yay def update_yay(): - print("\nUpdating AUR packages with Yay...\n") + print("\nUpdating AUR packages with Yay...") print("-------------------------------------") config_path = os.path.expanduser("~/.config/yay/") os.makedirs(config_path, exist_ok=True) From f0edccf0e5f8142ef00328ca4d86808c01bc62b8 Mon Sep 17 00:00:00 2001 From: Felipe Date: Wed, 21 Feb 2024 22:57:00 -0300 Subject: [PATCH 12/12] Updates - new futures --- src/upd8all_updater.py | 64 ++++++++++++++++++------------------------ 1 file changed, 28 insertions(+), 36 deletions(-) diff --git a/src/upd8all_updater.py b/src/upd8all_updater.py index 5186be5..a3642c6 100644 --- a/src/upd8all_updater.py +++ b/src/upd8all_updater.py @@ -20,41 +20,31 @@ def print_welcome_message(): """) # Function to execute a command with sudo as needed -def execute_command_with_sudo(command, sudo_password): - if command.startswith("sudo"): - master, slave = pty.openpty() - proc = subprocess.Popen( - command, - shell=True, - stdin=subprocess.PIPE, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - universal_newlines=True - ) - - # Send sudo password - sudo_prompt = proc.communicate(f"{sudo_password}\n")[1] - if "Sorry" in sudo_prompt: # If "Sorry" in sudo prompt, password was incorrect - print("Incorrect sudo password. Exiting.") - sys.exit(1) - - # Read output - stdout, stderr = proc.communicate() - print(stdout) - print(stderr) - else: - os.system(command) +def execute_command_with_sudo(command): + proc = subprocess.Popen( + ["sudo", "-S", *command.split()], + stdin=subprocess.PIPE, + stdout=sys.stdout, + stderr=sys.stderr, + universal_newlines=True + ) + + # Send sudo password + stdout, stderr = proc.communicate(input=sudo_password + '\n') + if proc.returncode != 0: + print(f"Error executing command with sudo: {command}") + sys.exit(1) # Function to update Pacman packages -def update_pacman(sudo_password): - print("Updating Pacman packages...") +def update_pacman(): + print("\nUpdating Pacman packages...") print("-------------------------------------") - command = "sudo pacman -Syu --noconfirm" - execute_command_with_sudo(command, sudo_password) + command = "pacman -Syu --noconfirm" + execute_command_with_sudo(command) # Function to update AUR packages with Yay -def update_yay(sudo_password): - print("Updating AUR packages with Yay...") +def update_yay(): + print("\nUpdating AUR packages with Yay...") print("-------------------------------------") config_path = os.path.expanduser("~/.config/yay/") os.makedirs(config_path, exist_ok=True) @@ -62,14 +52,13 @@ def update_yay(sudo_password): with open(config_file, "w") as f: json.dump({"misc": {"save": True}}, f) command = "yay -Syu --noconfirm" - execute_command_with_sudo(command, sudo_password) + execute_command_with_sudo(command) # Function to update packages with Homebrew def update_brew(): print("\nUpdating packages with Homebrew...") print("-------------------------------------") command = "brew update && brew upgrade" - os.system(command) print("\n-----------------------------------\n") @@ -91,10 +80,9 @@ def check_package_version(package, package_manager): # Function executed in a separate thread to show a warning message if no package name is entered within 1 minute def timeout_warning(): print("\nTime's up. Program execution has ended.\n") - sys.stdout.flush() # Limpiar el buffer de salida + sys.stdout.flush() # Flush the output buffer sys.exit(0) - def main(): # Print welcome message print_welcome_message() @@ -114,14 +102,15 @@ def main(): has_brew = False # Request sudo password at the start of the program + global sudo_password sudo_password = getpass.getpass(prompt="Enter your sudo password: ") print() # Add a newline after entering the password # Update packages - update_pacman(sudo_password) + update_pacman() if has_yay: - update_yay(sudo_password) + update_yay() else: print("You do not have Yay installed.") @@ -134,6 +123,9 @@ def main(): timer_thread = threading.Timer(60, timeout_warning) timer_thread.start() + # Inform the user about program termination after 1 minute of inactivity + print("\nNote: If no further input is provided within 1 minute, the program will terminate.\n") + # Request package name and package manager to check its version print("Select the package manager to check the version:") print("1. Pacman")