From 057721ec933fc439d9e9b9887dc69704cd49472e Mon Sep 17 00:00:00 2001 From: cui-gaoleng <562344211@qq.com> Date: Fri, 22 Nov 2024 12:14:08 +0800 Subject: [PATCH] =?UTF-8?q?fix=20progress=20bar=20has=20been=20at=20the=20?= =?UTF-8?q?87%=20position=20for=20a=20long=20time+=E4=B8=A4=E5=A4=84?= =?UTF-8?q?=E7=B9=81=E4=BD=93=E7=BF=BB=E8=AF=91=E8=A1=A5=E9=BD=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- calamares.desktop | 2 +- lang/calamares_zh_TW.ts | 6 +-- src/modules/packages/main.py | 70 +++++++++++++++++++------------- src/modules/packages/module.desc | 1 + src/modules/unpackfs/main.py | 24 ++++++++--- 5 files changed, 65 insertions(+), 38 deletions(-) diff --git a/calamares.desktop b/calamares.desktop index 9a1416e..9d33495 100644 --- a/calamares.desktop +++ b/calamares.desktop @@ -5,7 +5,7 @@ Name=Install System GenericName=System Installer Keywords=calamares;system;installer; TryExec=calamares -Exec=sh -c "pkexec calamares" +Exec=sh -c "pkexec calamares -style Adwaita" Comment=Calamares — System Installer Icon=calamares Terminal=false diff --git a/lang/calamares_zh_TW.ts b/lang/calamares_zh_TW.ts index 8689629..3cc473c 100644 --- a/lang/calamares_zh_TW.ts +++ b/lang/calamares_zh_TW.ts @@ -613,9 +613,9 @@ The system will reboot or you can enter the debug mode for further investigation - &Debug + &Try Now @button - 調試(&D) + 立即試用(&D) Do you really want to cancel the current install process? @@ -4526,7 +4526,7 @@ Output: language - + 語言 Open donations website diff --git a/src/modules/packages/main.py b/src/modules/packages/main.py index 8c165e8..1fbe276 100644 --- a/src/modules/packages/main.py +++ b/src/modules/packages/main.py @@ -138,10 +138,11 @@ class PackageManager(metaclass=abc.ABCMeta): self.install([packagedata], from_local=from_local, options=options) else: self.run(packagedata["pre-script"]) - if isinstance(packagedata["package"], list): - self.install(packagedata["package"], from_local=from_local, options=options) - else: - self.install([packagedata["package"]], from_local=from_local, options=options) + if "package" in packagedata: + if isinstance(packagedata["package"], list): + self.install(packagedata["package"], from_local=from_local, options=options) + else: + self.install([packagedata["package"]], from_local=from_local, options=options) if isinstance(packagedata["post-script"], list): for script in packagedata["post-script"]: self.run(script) @@ -787,41 +788,54 @@ def run_operations(pkgman, entry, options): names (strings) or package information dictionaries with pre- and post-scripts. """ - global group_packages, completed_packages, mode_packages - - if "source" in entry and entry["source"] == "packagechooser@packagechooser": - handle_packagechooser(entry) + global group_packages, completed_packages, mode_packages, custom_status_message for key in entry.keys(): package_list = subst_locale(entry[key]) + libcalamares.utils.warning(str(package_list)) group_packages = len(package_list) - if key == "install": - _change_mode(INSTALL) - pkgman.operation_install(package_list, options=options) - elif key == "try_install": + if key in ["install", "try_install", "localInstall"]: _change_mode(INSTALL) - pkgman.operation_try_install(package_list, options=options) - elif key == "remove": - _change_mode(REMOVE) - pkgman.operation_remove(package_list, options=options) - elif key == "try_remove": + for package in package_list: + custom_status_message = f"Installing package: {package}" + try: + if key == "localInstall": + pkgman.operation_install([package], from_local=True, options=options) + elif key == "try_install": + pkgman.operation_try_install([package], options=options) + else: + pkgman.operation_install([package], options=options) + except Exception as e: + libcalamares.utils.warning("Failed to install package {}: {}".format(package, str(e))) + + completed_packages += 1 + progress = completed_packages / total_packages + libcalamares.job.setprogress(progress) + libcalamares.utils.debug("Progress: {:.2f}, Package: {}".format(progress, package)) + elif key in ["remove", "try_remove"]: _change_mode(REMOVE) - pkgman.operation_try_remove(package_list, options=options) - elif key == "localInstall": - _change_mode(INSTALL) - pkgman.operation_install(package_list, from_local=True, options=options) - elif key == "source": - libcalamares.utils.debug("Package-list from {!s}".format(entry[key])) + for package in package_list: + try: + if key == "remove": + pkgman.operation_remove([package], options=options) + elif key == "try_remove": + pkgman.operation_try_remove([package], options=options) + except Exception as e: + libcalamares.utils.warning("Failed to remove package {}: {}".format(package, str(e))) + + completed_packages += 1 + progress = completed_packages / total_packages + libcalamares.job.setprogress(progress) + libcalamares.utils.debug("Progress: {:.2f}, Package: {}".format(progress, package)) else: libcalamares.utils.warning("Unknown package-operation key {!s}".format(key)) - completed_packages += len(package_list) - libcalamares.job.setprogress(completed_packages * 1.0 / total_packages) - libcalamares.utils.debug("Pretty name: {!s}, setting progress..".format(pretty_name())) + if "source" in entry and entry["source"] == "packagechooser@packagechooser": + packagemeta = handle_packagechooser() + pkgman.operation_install([packagemeta], from_local=True, options=options) group_packages = 0 - _change_mode(None) - + _change_mode(None) def run(): """ diff --git a/src/modules/packages/module.desc b/src/modules/packages/module.desc index 3e3053b..9529af6 100644 --- a/src/modules/packages/module.desc +++ b/src/modules/packages/module.desc @@ -5,3 +5,4 @@ type: "job" name: "packages" interface: "python" script: "main.py" +weight: 50 diff --git a/src/modules/unpackfs/main.py b/src/modules/unpackfs/main.py index 4148720..4c5518e 100644 --- a/src/modules/unpackfs/main.py +++ b/src/modules/unpackfs/main.py @@ -26,6 +26,8 @@ import libcalamares import platform import gettext + +import libcalamares.utils _ = gettext.translation("calamares-python", localedir=libcalamares.utils.gettext_path(), languages=libcalamares.utils.gettext_languages(), @@ -263,6 +265,7 @@ def file_copy(source, entry, progress_cb): progress_cb(num_files_copied, num_files_total_local) try: returncode = 0 + arch = platform.machine() libcalamares.utils.host_env_process_output(["mkdir", "-p", entry.destination + "/etc/yum.repos.d/"], output_cb) @@ -272,6 +275,7 @@ def file_copy(source, entry, progress_cb): libcalamares.utils.host_env_process_output(["cp", "-af", "/etc/add_selinux_policy.sh", entry.destination + "/etc/add_selinux_policy.sh"], output_cb) libcalamares.utils.host_env_process_output(["chmod", "+x", entry.destination + "/etc/add_selinux_policy.sh"], output_cb) + completed_packages = 0 if os.path.exists("/etc/yum.repos.d/local.repo"): libcalamares.utils.host_env_process_output( ["cp", "-af", "/etc/yum.repos.d/local.repo", entry.destination + "/etc/yum.repos.d/"], output_cb) @@ -281,9 +285,13 @@ def file_copy(source, entry, progress_cb): else: packages = ["yum", "grub2", "grub2-efi-x64", "grub2-pc", "passwd", "sudo"] - libcalamares.utils.host_env_process_output( - ["yum", "--installroot=" + entry.destination, "--disablerepo=*", "--enablerepo=local-repo", - "--releasever=/", "--nogpgcheck", "--setopt=sslverify=0", "install", "-y"] + packages, output_cb) + for package in packages: + libcalamares.job.setprogress(completed_packages / len(packages)) + libcalamares.utils.host_env_process_output( + ["yum", "--installroot=" + entry.destination, "--disablerepo=*", "--enablerepo=local-repo", + "--releasever=/", "--nogpgcheck", "--setopt=sslverify=0", "install", "-y", package], output_cb) + completed_packages += 1 + libcalamares.job.setprogress(completed_packages / len(packages)) else: libcalamares.utils.host_env_process_output( ["cp", "-af", "/etc/yum.repos.d/openEuler.repo", entry.destination + "/etc/yum.repos.d/"], output_cb) @@ -292,9 +300,13 @@ def file_copy(source, entry, progress_cb): else: packages = ["yum", "grub2", "grub2-efi-x64", "grub2-pc", "passwd", "sudo"] - libcalamares.utils.host_env_process_output( - ["yum", "--installroot=" + entry.destination, "--releasever=/", "--nogpgcheck", "--setopt=sslverify=0", - "install", "-y"] + packages, output_cb) + for package in packages: + libcalamares.job.setprogress(completed_packages / len(packages)) + libcalamares.utils.host_env_process_output( + ["yum", "--installroot=" + entry.destination, "--releasever=/", "--nogpgcheck", "--setopt=sslverify=0", + "install", "-y", package], output_cb) + completed_packages += 1 + libcalamares.job.setprogress(completed_packages / len(packages)) libcalamares.utils.host_env_process_output(["rm", "-f", entry.destination + "/etc/shadow"], output_cb) libcalamares.utils.host_env_process_output(["cp", "-af", "/etc/shadow", entry.destination + "/etc/shadow"], output_cb) -- 2.43.0