Skip to content

Commit

Permalink
silence shell output from copy_to_host and copy_from_host
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisTimperley committed May 24, 2024
1 parent 6efa1a6 commit 82d703f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
v0.6.1 (2024-05-23)
--------------------

* silence stdout/stderr when copying files via `copy_to_host` and `copy_from_host`


v0.6.0 (2024-05-20)
-------------------

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "dockerblade"
version = "0.6.0"
version = "0.6.1"
description = "Interact with Docker containers via Python-like APIs"
authors = ["Chris Timperley <[email protected]>"]
license = "Apache-2.0"
Expand Down
22 changes: 19 additions & 3 deletions src/dockerblade/files.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import typing
from collections.abc import Iterator
from pathlib import Path
from subprocess import DEVNULL
from typing import Literal, overload

import attr
Expand Down Expand Up @@ -74,7 +75,13 @@ def copy_from_host(self, path_host: str, path_container: str) -> None:
cmd: str = (f"docker cp -L {path_host_escaped} "
f"{id_container}:{path_container_escaped}")
try:
subprocess.check_call(cmd, shell=True)
subprocess.check_call(
cmd,
shell=True,
stdin=DEVNULL,
stdout=DEVNULL,
stderr=DEVNULL,
)
except subprocess.CalledProcessError as error:
path_container_parent: str = os.path.dirname(path_container)
if not self.isdir(path_container_parent):
Expand Down Expand Up @@ -129,7 +136,13 @@ def copy_to_host(self,
f"{id_container}:{path_container_escaped} "
f"{path_host_escaped}")
try:
subprocess.check_call(cmd, shell=True)
subprocess.check_call(
cmd,
shell=True,
stdin=DEVNULL,
stdout=DEVNULL,
stderr=DEVNULL,
)
except subprocess.CalledProcessError as error:
if not self.exists(path_container):
raise exc.ContainerFileNotFound(
Expand Down Expand Up @@ -206,7 +219,10 @@ def rmdir(self, directory: str) -> None:
f"test -d {escaped_directory} || exit 51 && "
f"rmdir {escaped_directory}")
try:
self._shell.check_output(command, text=True)
self._shell.check_output(
command,
text=True,
)
except exc.CalledProcessError as error:
if error.returncode == EXIT_CODE_FILE_NOT_FOUND:
raise exc.ContainerFileNotFound(
Expand Down
2 changes: 1 addition & 1 deletion src/dockerblade/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "0.6.0"
__version__ = "0.6.1"

0 comments on commit 82d703f

Please sign in to comment.