Skip to content

Commit

Permalink
Merge pull request #19 from felipealfonsog/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
felipealfonsog authored Feb 22, 2024
2 parents 1429037 + f0edccf commit 99bfbf2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 72 deletions.
64 changes: 28 additions & 36 deletions src/upd8all_updater.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,56 +20,45 @@ 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)
config_file = os.path.join(config_path, "config.json")
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")

Expand All @@ -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()
Expand All @@ -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.")

Expand All @@ -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")
Expand Down
64 changes: 28 additions & 36 deletions src/upd8all_updater_unstable.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,56 +20,45 @@ 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)
config_file = os.path.join(config_path, "config.json")
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")

Expand All @@ -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()
Expand All @@ -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.")

Expand All @@ -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")
Expand Down

0 comments on commit 99bfbf2

Please sign in to comment.