Merge pull request #1833 from dalto8/pacman

[packages] Additional pacman options
This commit is contained in:
Adriaan de Groot 2021-11-29 11:39:01 +01:00 committed by GitHub
commit 90459e434f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 71 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,73 @@ 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, callback=False):
"""
Call pacman in a loop until it is successful or the number of retries is exceeded
:param command: The pacman command to run
:param callback: An optional boolean that indicates if this pacman run should use the callback
:return:
"""
pacman_count = 0
while pacman_count <= self.pacman_num_retries:
pacman_count += 1
try:
if callback is True:
libcalamares.utils.target_env_process_output(command, self.line_cb)
else:
libcalamares.utils.target_env_process_output(command)
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.reset_progress()
libcalamares.utils.target_env_process_output(["pacman", pacman_flags,
"--noconfirm"] + pkgs, self.line_cb)
self.run_pacman(command, True)
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, True)
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):

View File

@ -62,6 +62,22 @@ skip_if_no_internet: false
update_db: true
update_system: false
# pacman specific options
#
# pacman_num_retries should be a positive integer which sepcifies the
# number of times the call to pacman will be retried in the event of a
# failure. If it is missing, it will be set to 0
#
# pacman_disable_download_timeout is a boolean that, when true, includes
# the flag --disable-download-timeout on calls to pacman. When missing,
# false is assumed
#
# pacman_needed_only is a boolean that includes the pacman argument --needed
# when set to true. If missing, false is assumed
pacman_num_retries: 0
pacman_disable_download_timeout: false
pacman_needed_only: false
#
# List of maps with package operations such as install or remove.
# Distro developers can provide a list of packages to remove

View File

@ -26,6 +26,10 @@ properties:
update_system: { type: boolean, default: false }
skip_if_no_internet: { type: boolean, default: false }
pacman_num_retries: { type: integer, default: 0 }
pacman_disable_download_timeout: { type: boolean, default: false }
pacman_needed_only: { type: boolean, default: false }
operations:
type: array
items: