From e1a93987d01536369e41159ed779d11d48e794ad Mon Sep 17 00:00:00 2001 From: Adriaan de Groot Date: Wed, 30 Aug 2017 10:08:44 -0400 Subject: [PATCH] Packages module: add progress reporting Adds i18n to the module (but these strings are not yet extracted), and reports progress as each group of packages is installed. FIXES #781 --- src/modules/packages/main.py | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py index 9eb0a8ea0..623344384 100644 --- a/src/modules/packages/main.py +++ b/src/modules/packages/main.py @@ -28,6 +28,22 @@ import subprocess import libcalamares from libcalamares.utils import check_target_env_call, target_env_call +import gettext +_ = gettext.translation("calamares-python", + localedir=libcalamares.utils.gettext_path(), + languages=libcalamares.utils.gettext_languages(), + fallback=True).gettext + + +total_packages = 0 +completed_packages = 0 + +def pretty_name(): + if (not (total_packages and completed_packages)) + return _("Install packages.") + else + return _("Installing packages, {} of {}.").format(str(completed_packages), str(total_packages)) + class PackageManager(metaclass=abc.ABCMeta): """ @@ -306,6 +322,15 @@ def run_operations(pkgman, entry): :param pkgman: :param entry: """ + global total_packages, completed_packages + total_packages = 0 + completed_packages = 0 + for packagelist in entry.values(): + total_packages += len(packagelist) + if not total_packages: + # Avoids potential divide-by-zero in progress reporting + return + for key in entry.keys(): entry[key] = subst_locale(entry[key]) if key == "install": @@ -337,6 +362,9 @@ def run_operations(pkgman, entry): elif key == "localInstall": pkgman.install(entry[key], from_local=True) + completed_packages += len(entry[key]) + libcalamares.job.setprogress(completed_packages * 1.0 / total_packages) + def run(): """