mirror of
https://github.com/Snigdha-OS/snigdhaos-welcome.git
synced 2025-09-21 06:24:56 +02:00
⚡️ perf(_rate_m): add option to install rate mirrors
This commit is contained in:
@@ -596,48 +596,79 @@ class Main(Gtk.Window):
|
|||||||
return False
|
return False
|
||||||
|
|
||||||
def mirror_update(self):
|
def mirror_update(self):
|
||||||
|
# Function to check if rate-mirrors is installed
|
||||||
|
def is_rate_mirrors_installed():
|
||||||
|
try:
|
||||||
|
# Check if rate-mirrors is available in the system path
|
||||||
|
subprocess.run(["which", "rate-mirrors"], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
return True # If found, return True
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
return False # If not found, return False
|
||||||
|
|
||||||
|
# If rate-mirrors is not installed, install it
|
||||||
|
if not is_rate_mirrors_installed():
|
||||||
|
GLib.idle_add(
|
||||||
|
self.label_notify.set_markup,
|
||||||
|
f"<span foreground='yellow'>rate-mirrors not found. Installing...</span>"
|
||||||
|
)
|
||||||
|
# Install rate-mirrors using pacman
|
||||||
|
try:
|
||||||
|
subprocess.run(["sudo", "pacman", "-S", "--noconfirm", "rate-mirrors"], check=True)
|
||||||
|
print("rate-mirrors installed successfully.")
|
||||||
|
except subprocess.CalledProcessError as e:
|
||||||
|
print(f"Error installing rate-mirrors: {e}")
|
||||||
|
GLib.idle_add(
|
||||||
|
self.label_notify.set_markup,
|
||||||
|
f"<span foreground='red'>Error installing rate-mirrors. Please install manually.</span>"
|
||||||
|
)
|
||||||
|
return
|
||||||
|
|
||||||
|
# Begin updating the Arch mirrorlist
|
||||||
GLib.idle_add(
|
GLib.idle_add(
|
||||||
self.label_notify.set_markup,
|
self.label_notify.set_markup,
|
||||||
f"<span foreground='cyan'>Updating Arch Mirrorlist\n"
|
f"<span foreground='cyan'>Updating Arch Mirrorlist\n"
|
||||||
f"This may take some time, please wait...</span>",
|
f"This may take some time, please wait...</span>",
|
||||||
) # noqa
|
) # noqa
|
||||||
GLib.idle_add(self.button_mirrors.set_sensitive, False)
|
GLib.idle_add(self.button_mirrors.set_sensitive, False)
|
||||||
|
|
||||||
|
# Run the mirror update for Arch
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
[
|
[
|
||||||
"pkexec",
|
"pkexec", # Runs the command with elevated privileges
|
||||||
"rate-mirrors",
|
"rate-mirrors",
|
||||||
"--concurrency",
|
"--concurrency", "40", # Use 40 threads for faster updates
|
||||||
"40",
|
"--disable-comments", # Ignore comments in the mirrorlist
|
||||||
"--disable-comments",
|
"--allow-root", # Allow root privileges for the operation
|
||||||
"--allow-root",
|
"--save", "/etc/pacman.d/mirrorlist", # Save the updated mirrorlist
|
||||||
"--save",
|
"arch", # The mirrorlist to update (Arch Linux)
|
||||||
"/etc/pacman.d/mirrorlist",
|
],
|
||||||
"arch",
|
|
||||||
],
|
|
||||||
shell=False,
|
shell=False,
|
||||||
)
|
)
|
||||||
print("Update mirrors completed")
|
print("Arch mirrorlist update completed")
|
||||||
|
|
||||||
|
# Update the notify label for Chaotic AUR mirrorlist
|
||||||
GLib.idle_add(
|
GLib.idle_add(
|
||||||
self.label_notify.set_markup,
|
self.label_notify.set_markup,
|
||||||
f"<span foreground='cyan'>Updating Chaotic Aur Mirrorlist\n"
|
f"<span foreground='cyan'>Updating Chaotic Aur Mirrorlist\n"
|
||||||
f"This may take some time, please wait...</span>",
|
f"This may take some time, please wait...</span>",
|
||||||
) # noqa
|
) # noqa
|
||||||
GLib.idle_add(self.button_mirrors.set_sensitive, False)
|
|
||||||
|
# Run the mirror update for Chaotic AUR
|
||||||
subprocess.run(
|
subprocess.run(
|
||||||
[
|
[
|
||||||
"pkexec",
|
"pkexec", # Elevated privileges for the operation
|
||||||
"/usr/bin/rate-mirrors",
|
"/usr/bin/rate-mirrors", # Full path to rate-mirrors for Chaotic AUR
|
||||||
"--concurrency",
|
"--concurrency", "40", # Use 40 threads for faster updates
|
||||||
"40",
|
"--disable-comments", # Ignore comments in the mirrorlist
|
||||||
"--disable-comments",
|
"--allow-root", # Allow root privileges for the operation
|
||||||
"--allow-root",
|
"--save", "/etc/pacman.d/chaotic-mirrorlist", # Save the updated mirrorlist
|
||||||
"--save",
|
"chaotic-aur", # The mirrorlist to update (Chaotic AUR)
|
||||||
"/etc/pacman.d/chaotic-mirrorlist",
|
|
||||||
"chaotic-aur",
|
|
||||||
],
|
],
|
||||||
shell=False,
|
shell=False,
|
||||||
)
|
)
|
||||||
print("Update mirrors completed")
|
print("Chaotic AUR mirrorlist update completed")
|
||||||
|
|
||||||
|
# Finalize the mirror update and enable the button
|
||||||
GLib.idle_add(self.label_notify.set_markup, "<b>Mirrorlist updated</b>")
|
GLib.idle_add(self.label_notify.set_markup, "<b>Mirrorlist updated</b>")
|
||||||
GLib.idle_add(self.button_mirrors.set_sensitive, True)
|
GLib.idle_add(self.button_mirrors.set_sensitive, True)
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user