From a0b970e4e6d7c36f358f8e28af69db6fa5f39871 Mon Sep 17 00:00:00 2001 From: Umit Kablan Date: Mon, 7 Oct 2024 12:25:22 +0300 Subject: [PATCH] comments: rstrip('\n'), func name --- pleskdistup/common/src/dpkg.py | 15 ++++++++------- pleskdistup/common/src/util.py | 6 +++--- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pleskdistup/common/src/dpkg.py b/pleskdistup/common/src/dpkg.py index cb74c61..71c5cdc 100644 --- a/pleskdistup/common/src/dpkg.py +++ b/pleskdistup/common/src/dpkg.py @@ -126,7 +126,7 @@ def safely_install_packages( install_packages(pkgs, repository, force_package_config) -def apt_get_retry_temp_fails( +def exec_retry_when_locked( apt_get_cmd: typing.List[str], tmpfail_retry_intervals: typing.Optional[typing.List[int]] = None, collect_stdout: bool = False, @@ -160,6 +160,7 @@ def process_stderr(line: str) -> None: "PATH": os.environ["PATH"], "DEBIAN_FRONTEND": "noninteractive", "LC_ALL": "C", + "LANG": "C", }, ) if exit_code == 0: @@ -186,7 +187,7 @@ def remove_packages( if simulate: cmd.append("--simulate") cmd += pkgs - cmd_out = apt_get_retry_temp_fails(cmd, tmpfail_retry_intervals, collect_stdout=True) + cmd_out = exec_retry_when_locked(cmd, tmpfail_retry_intervals, collect_stdout=True) if simulate: return _parse_apt_get_simulation(cmd_out) return None @@ -212,7 +213,7 @@ def find_related_repofiles(repository_file: str) -> typing.List[str]: def update_package_list(tmpfail_retry_intervals: typing.Optional[typing.List[int]] = None) -> None: cmd = ["/usr/bin/apt-get", "update", "-y"] - apt_get_retry_temp_fails(cmd, tmpfail_retry_intervals) + exec_retry_when_locked(cmd, tmpfail_retry_intervals) def upgrade_packages( @@ -223,12 +224,12 @@ def upgrade_packages( pkgs = [] cmd = ["/usr/bin/apt-get", "upgrade", "-y"] + APT_CHOOSE_OLD_FILES_OPTIONS + pkgs - apt_get_retry_temp_fails(cmd, tmpfail_retry_intervals) + exec_retry_when_locked(cmd, tmpfail_retry_intervals) def autoremove_outdated_packages(tmpfail_retry_intervals: typing.Optional[typing.List[int]] = None) -> None: cmd = ["/usr/bin/apt-get", "autoremove", "-y"] - apt_get_retry_temp_fails(cmd, tmpfail_retry_intervals) + exec_retry_when_locked(cmd, tmpfail_retry_intervals) def depconfig_parameter_set(parameter: str, value: str) -> None: @@ -244,12 +245,12 @@ def depconfig_parameter_get(parameter: str) -> str: def restore_installation(tmpfail_retry_intervals: typing.Optional[typing.List[int]] = None) -> None: cmd = ["/usr/bin/apt-get", "-f", "install", "-y"] - apt_get_retry_temp_fails(cmd, tmpfail_retry_intervals) + exec_retry_when_locked(cmd, tmpfail_retry_intervals) def do_distupgrade(tmpfail_retry_intervals: typing.Optional[typing.List[int]] = None) -> None: cmd = ["apt-get", "dist-upgrade", "-y"] + APT_CHOOSE_OLD_FILES_OPTIONS - apt_get_retry_temp_fails(cmd, tmpfail_retry_intervals) + exec_retry_when_locked(cmd, tmpfail_retry_intervals) def get_installed_packages_list(regex: str) -> typing.List[typing.Tuple[str, str]]: diff --git a/pleskdistup/common/src/util.py b/pleskdistup/common/src/util.py index c0c7c0c..c073e49 100644 --- a/pleskdistup/common/src/util.py +++ b/pleskdistup/common/src/util.py @@ -52,19 +52,19 @@ def exec_get_output_streamed( process.communicate() return process.returncode - while None is process.poll(): + while process.poll() is None: if process_stdout_line is not None: if not process.stdout: raise RuntimeError(f"Cannot get process stdout of command {cmd!r}") line = process.stdout.readline() if line: - process_stdout_line(line.rstrip()) + process_stdout_line(line.rstrip('\n')) if process_stderr_line is not None: if not process.stderr: raise RuntimeError(f"Cannot get process stderr of command {cmd!r}") line = process.stderr.readline() if line: - process_stderr_line(line.rstrip()) + process_stderr_line(line.rstrip('\n')) return process.returncode