From e4b44b5f851441c62f835dd788c747c12c40de77 Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Tue, 9 Nov 2021 14:42:12 +0100 Subject: [PATCH] [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):