Skip to content

Commit

Permalink
comments: rstrip('\n'), func name
Browse files Browse the repository at this point in the history
  • Loading branch information
Umit Kablan committed Oct 7, 2024
1 parent 9a8967c commit a0b970e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
15 changes: 8 additions & 7 deletions pleskdistup/common/src/dpkg.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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
Expand All @@ -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(
Expand All @@ -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:
Expand All @@ -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]]:
Expand Down
6 changes: 3 additions & 3 deletions pleskdistup/common/src/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down

0 comments on commit a0b970e

Please sign in to comment.