From 4821f450f384c972dd9e4f249bfe6f8c86f3abe1 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 9 Nov 2021 13:07:29 +0100 Subject: [PATCH 1/3] [packages] Report progress by scanning pacman output - during install and remove, check for (n/m) output lines which report progress of the pacman actions and turn those into progress reports for the *packages* module. --- src/modules/packages/main.py | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py index 7d383b552..3d60956f5 100644 --- a/src/modules/packages/main.py +++ b/src/modules/packages/main.py @@ -370,17 +370,33 @@ class PMPackageKit(PackageManager): class PMPacman(PackageManager): backend = "pacman" + def __init__(self): + import re + progress_match = re.compile("^\\((\\d+)/(\\d+)\\)") + def line_cb(line): + global completed_packages, group_packages + if line.startswith("("): + m = progress_match.match(line) + if m: + try: + completed_packages = int(m.groups()[0]) + group_packages = int(m.groups()[1]) + libcalamares.job.setprogress(completed_packages / group_packages) + except ValueError as e: + pass + self.line_cb = line_cb + def install(self, pkgs, from_local=False): if from_local: pacman_flags = "-U" else: pacman_flags = "-S" - check_target_env_call(["pacman", pacman_flags, - "--noconfirm"] + pkgs) + libcalamares.utils.target_env_process_output(["pacman", pacman_flags, + "--noconfirm"] + pkgs, self.line_cb) def remove(self, pkgs): - check_target_env_call(["pacman", "-Rs", "--noconfirm"] + pkgs) + libcalamares.utils.target_env_process_output(["pacman", "-Rs", "--noconfirm"] + pkgs, self.line_cb) def update_db(self): check_target_env_call(["pacman", "-Sy"]) From e4b44b5f851441c62f835dd788c747c12c40de77 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 9 Nov 2021 14:42:12 +0100 Subject: [PATCH 2/3] [packages] Look for other progress indicators - the (n/m) lines are output of specific steps, not actual package- installation. So look for " ..." lines instead. This means we keep some state around, and need extra machinery to report those lines rather than the generic progress reporting that reports on groups. --- src/modules/packages/main.py | 37 ++++++++++++++++++++++++++---------- 1 file changed, 27 insertions(+), 10 deletions(-) diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py index 3d60956f5..f35614911 100644 --- a/src/modules/packages/main.py +++ b/src/modules/packages/main.py @@ -35,6 +35,10 @@ total_packages = 0 # For the entire job completed_packages = 0 # Done so far for this job group_packages = 0 # One group of packages from an -install or -remove entry +# A PM object may set this to a string (take care of translations!) +# to override the string produced by pretty_status_message() +custom_status_message = None + INSTALL = object() REMOVE = object() mode_packages = None # Changes to INSTALL or REMOVE @@ -51,6 +55,8 @@ def pretty_name(): def pretty_status_message(): + if custom_status_message is not None: + return custom_status_message if not group_packages: if (total_packages > 0): # Outside the context of an operation @@ -374,28 +380,39 @@ class PMPacman(PackageManager): import re progress_match = re.compile("^\\((\\d+)/(\\d+)\\)") def line_cb(line): - global completed_packages, group_packages - if line.startswith("("): - m = progress_match.match(line) - if m: - try: - completed_packages = int(m.groups()[0]) - group_packages = int(m.groups()[1]) - libcalamares.job.setprogress(completed_packages / group_packages) - except ValueError as e: - pass + if line.startswith(":: "): + self.in_package_changes = "package changes" in line + else: + if self.in_package_changes and line.endswith("...\n"): + # Update the message, untranslated; do not change the + # progress percentage, since there may be more "installing..." + # lines in the output for the group, than packages listed + # explicitly. We don't know how to calculate proper progress. + global custom_status_message + custom_status_message = line.strip() + libcalamares.job.setprogress(self.progress_fraction) + libcalamares.utils.debug(line) + + self.in_package_changes = False self.line_cb = line_cb + def reset_progress(self): + self.in_package_changes = False + # These are globals + self.progress_fraction = (completed_packages * 1.0 / total_packages) + def install(self, pkgs, from_local=False): if from_local: pacman_flags = "-U" else: pacman_flags = "-S" + 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) def update_db(self): From 2a86e86817e0592815769893f790e5f161f0e6fa Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 9 Nov 2021 15:25:06 +0100 Subject: [PATCH 3/3] [packages] Make package-installation messages slightly less scary. From a test with XeroLinux, at some point it says 'reinstalling linux...' which is a message from pacman about the package called 'linux'. --- src/modules/packages/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py index f35614911..98faa9b63 100644 --- a/src/modules/packages/main.py +++ b/src/modules/packages/main.py @@ -389,7 +389,7 @@ class PMPacman(PackageManager): # lines in the output for the group, than packages listed # explicitly. We don't know how to calculate proper progress. global custom_status_message - custom_status_message = line.strip() + custom_status_message = "pacman: " + line.strip() libcalamares.job.setprogress(self.progress_fraction) libcalamares.utils.debug(line)