[packages] Add support for more pacman options

This commit is contained in:
dalto 2021-11-25 11:52:41 -06:00
parent 01d55254f2
commit fa10bb8dd3
3 changed files with 62 additions and 7 deletions

View file

@ -379,6 +379,7 @@ class PMPacman(PackageManager):
def __init__(self):
import re
progress_match = re.compile("^\\((\\d+)/(\\d+)\\)")
def line_cb(line):
if line.startswith(":: "):
self.in_package_changes = "package changes" in line
@ -396,30 +397,64 @@ class PMPacman(PackageManager):
self.in_package_changes = False
self.line_cb = line_cb
self.pacman_num_retries = libcalamares.job.configuration.get("pacman_num_retries", 0)
self.pacman_disable_timeout = libcalamares.job.configuration.get("pacman_disable_download_timeout", False)
self.pacman_needed_only = libcalamares.job.configuration.get("pacman_needed_only", False)
def reset_progress(self):
self.in_package_changes = False
# These are globals
self.progress_fraction = (completed_packages * 1.0 / total_packages)
def run_pacman(self, command):
# Call pacman in a loop until it is successful or the number of retries is exceeded
pacman_count = 0
while pacman_count <= self.pacman_num_retries:
pacman_count += 1
try:
libcalamares.utils.target_env_process_output(command, self.line_cb)
return
except subprocess.CalledProcessError:
if pacman_count <= self.pacman_num_retries:
pass
else:
raise
def install(self, pkgs, from_local=False):
command = ["pacman"]
if from_local:
pacman_flags = "-U"
command.append("-U")
else:
pacman_flags = "-S"
command.append("-S")
command.append("--noconfirm")
if self.pacman_needed_only is True:
command.append("--needed")
if self.pacman_disable_timeout is True:
command.append("--disable-download-timeout")
command += pkgs
self.run_pacman(command)
self.reset_progress()
libcalamares.utils.target_env_process_output(["pacman", pacman_flags,
"--noconfirm"] + pkgs, self.line_cb)
def remove(self, pkgs):
self.reset_progress()
libcalamares.utils.target_env_process_output(["pacman", "-Rs", "--noconfirm"] + pkgs, self.line_cb)
self.run_pacman(["pacman", "-Rs", "--noconfirm"] + pkgs)
def update_db(self):
check_target_env_call(["pacman", "-Sy"])
self.run_pacman(["pacman", "-Sy"])
def update_system(self):
check_target_env_call(["pacman", "-Su", "--noconfirm"])
command = ["pacman", "-Su", "--noconfirm"]
if self.pacman_disable_timeout is True:
command.append("--disable-download-timeout")
self.run_pacman(command)
class PMPamac(PackageManager):