Skip to content

Commit

Permalink
Merge pull request #37 from felipealfonsog/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
felipealfonsog committed Feb 23, 2024
2 parents a76c325 + ffc2b5c commit 1bdd81c
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 153 deletions.
79 changes: 42 additions & 37 deletions src/upd8all_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,10 @@ def check_package_version(package, package_manager):
return

print(f"Checking version of {package} using {package_manager}...")
os.system(command)
result = os.system(command)
if result != 0:
print(f"No package named '{package}' found in the system.")
sys.exit(1)

# Handler for the alarm signal
def alarm_handler(signum, frame):
Expand All @@ -113,7 +116,6 @@ def main():

# Set up the alarm signal
signal.signal(signal.SIGALRM, alarm_handler)
signal.alarm(60) # Set the alarm to trigger after 60 seconds

# Check if the user has yay installed
try:
Expand All @@ -133,42 +135,50 @@ def main():
sudo_password = getpass.getpass(prompt="Enter your sudo password: ")
print() # Add a newline after entering the password

# Update packages
update_pacman(sudo_password)

if has_yay:
update_yay(sudo_password)
else:
print("You do not have Yay installed.")

if has_brew:
update_brew()
else:
print("You do not have Brew installed.")
while True:
signal.alarm(60) # Set the alarm to trigger after 60 seconds

# 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")
# Update packages
update_pacman(sudo_password)

while True:
# Request package name and package manager to check its version
print("Select the package manager to check the version:")
print("1. Pacman")
if has_yay:
print("2. Yay")
if has_brew:
print("3. Brew")
update_yay(sudo_password)
else:
print("You do not have Yay installed.")

selected_option = input("Enter the option number (e.g., 1) or 'q' to quit: ").strip().lower()
if has_brew:
update_brew()
else:
print("You do not have Brew installed.")

# Check if the timer has expired
if not signal.getitimer(signal.ITIMER_REAL)[0]:
print("\nTime's up. Program execution has ended.\n")
sys.exit(0)
# 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")

# Check if the user wants to quit
if selected_option == 'q':
print("\nExiting the program.\n")
sys.exit(0)
# Request package name and package manager to check its version
while True:
print("Select the package manager to check the version:")
print("1. Pacman")
if has_yay:
print("2. Yay")
if has_brew:
print("3. Brew")

selected_option = input("Enter the option number (e.g., 1) or 'q' to quit: ").strip().lower()

# Check if the timer has expired
if not signal.getitimer(signal.ITIMER_REAL)[0]:
print("\nTime's up. Program execution has ended.\n")
sys.exit(0)

# Check if the user wants to quit
if selected_option == 'q':
print("\nExiting the program.\n")
sys.exit(0)

if selected_option in ['1', '2', '3']:
break
else:
print("\nInvalid option. Please enter a valid option number or 'q' to quit.\n")

package_manager = ""
if selected_option == '1':
Expand All @@ -177,17 +187,12 @@ def main():
package_manager = "yay"
elif selected_option == '3' and has_brew:
package_manager = "brew"
else:
print("\nInvalid option. Please enter a valid option number or 'q' to quit.\n")
continue

# Request package name
package = input("Enter the name of the package to check its version (e.g., gh): ").strip().lower()

# Check the version of the specified package
check_package_version(package, package_manager)
break

if __name__ == "__main__":
main()

162 changes: 86 additions & 76 deletions src/upd8all_updater_stable.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,38 @@
import os
import sys
import threading
import getpass
import subprocess
import select
import json
import signal

# Function to print the welcome message
def print_welcome_message():
print("""
Welcome to the Upd8All Updater
Welcome to the Upd8All Updater
=======================================
Description: Upd8All is a versatile and comprehensive package update tool meticulously
crafted to cater to the needs of Arch Linux users.
Creator: Felipe Alfonso Gonzalez - github.com/felipealfonsog - f.alfonso@res-ear.ch
License: BSD 3-Clause (Restrictive)
***************************************************************************
crafted to cater to the needs of Arch Linux users. No more worried about sudo, and continuous
updating of the system with pacman, yay, and brew (You can even configure this as a service).
-------------------------------------------------------------------------------------
Creator/Engineer: Felipe Alfonso Gonzalez - github.com/felipealfonsog - f.alfonso@res-ear.ch
License: BSD 3-Clause (Restrictive: Ask about it)
Developed with love from Chile.
*************************************************************************************
""")

# Function to execute a command with sudo as needed
def execute_command_with_sudo(command, sudo_password):
# Set environment variable to prevent sudo from asking for password
env = os.environ.copy()
env['SUDO_ASKPASS'] = '/bin/false'

proc = subprocess.Popen(
["sudo", "-S", *command.split()],
stdin=subprocess.PIPE,
stdout=sys.stdout,
stderr=sys.stderr,
universal_newlines=True
universal_newlines=True,
env=env # Pass the modified environment variable
)

# Send sudo password
Expand All @@ -45,7 +52,6 @@ def update_pacman(sudo_password):
command = "pacman -Syu --noconfirm"
execute_command_with_sudo(command, sudo_password)


# Function to update AUR packages with Yay
def update_yay(sudo_password):
print("\nUpdating AUR packages with Yay...")
Expand All @@ -58,30 +64,28 @@ def update_yay(sudo_password):

command = "yay -Syu --noconfirm"

# Verificar si se necesita sudo para el comando Yay
# Check if sudo is required for the Yay command
need_sudo = False
try:
subprocess.run(command.split(), stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
except subprocess.CalledProcessError:
need_sudo = True

if need_sudo:
# Ejecutar el comando Yay con sudo si es necesario
# Execute the Yay command with sudo if necessary
execute_command_with_sudo(command, sudo_password)
else:
# Ejecutar el comando Yay directamente sin sudo
# Execute the Yay command directly without sudo
os.system(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")

# Function to check the version of a package in a specific package manager
def check_package_version(package, package_manager):
if package_manager == "pacman":
Expand All @@ -95,18 +99,23 @@ def check_package_version(package, package_manager):
return

print(f"Checking version of {package} using {package_manager}...")
os.system(command)
result = os.system(command)
if result != 0:
print(f"No package named '{package}' found in the system.")
sys.exit(1)

# Function executed in a separate thread to show a warning message if no package name is entered within 1 minute
def timeout_warning():
# Handler for the alarm signal
def alarm_handler(signum, frame):
print("\nTime's up. Program execution has ended.\n")
sys.stdout.flush() # Flush the output buffer
sys.exit(0)

def main():
# Print welcome message
print_welcome_message()

# Set up the alarm signal
signal.signal(signal.SIGALRM, alarm_handler)

# Check if the user has yay installed
try:
subprocess.run(["yay", "--version"], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL, check=True)
Expand All @@ -122,66 +131,67 @@ 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)

if has_yay:
update_yay(sudo_password)
else:
print("You do not have Yay installed.")

if has_brew:
update_brew()
else:
print("You do not have Brew installed.")

# Start timing thread
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")
if has_yay:
print("2. Yay")
if has_brew:
print("3. Brew")

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")
timer_thread.cancel() # Cancel the timer immediately
sys.exit(0)

package_manager = ""
if selected_option == '1':
package_manager = "pacman"
elif selected_option == '2' and has_yay:
package_manager = "yay"
elif selected_option == '3' and has_brew:
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
timer_thread.cancel()

# Request package name
package = input("Enter the name of the package to check its version (e.g., gh): ").strip().lower()

# Check the version of the specified package
check_package_version(package, package_manager)
while True:
signal.alarm(60) # Set the alarm to trigger after 60 seconds

# Update packages
update_pacman(sudo_password)

if has_yay:
update_yay(sudo_password)
else:
print("You do not have Yay installed.")

if has_brew:
update_brew()
else:
print("You do not have Brew installed.")

# 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
while True:
print("Select the package manager to check the version:")
print("1. Pacman")
if has_yay:
print("2. Yay")
if has_brew:
print("3. Brew")

selected_option = input("Enter the option number (e.g., 1) or 'q' to quit: ").strip().lower()

# Check if the timer has expired
if not signal.getitimer(signal.ITIMER_REAL)[0]:
print("\nTime's up. Program execution has ended.\n")
sys.exit(0)

# Check if the user wants to quit
if selected_option == 'q':
print("\nExiting the program.\n")
sys.exit(0)

if selected_option in ['1', '2', '3']:
break
else:
print("\nInvalid option. Please enter a valid option number or 'q' to quit.\n")

package_manager = ""
if selected_option == '1':
package_manager = "pacman"
elif selected_option == '2' and has_yay:
package_manager = "yay"
elif selected_option == '3' and has_brew:
package_manager = "brew"

# Request package name
package = input("Enter the name of the package to check its version (e.g., gh): ").strip().lower()

# Check the version of the specified package
check_package_version(package, package_manager)

if __name__ == "__main__":
main()
Loading

0 comments on commit 1bdd81c

Please sign in to comment.