Skip to content

Commit 41e123f

Browse files
committed
documentation and bugfixes
Signed-off-by: Bogaert Aaron <[email protected]>
1 parent fe6a246 commit 41e123f

File tree

1 file changed

+20
-14
lines changed

1 file changed

+20
-14
lines changed

src/pythainer/builders/cmds.py

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@
99
and package managers.
1010
"""
1111

12-
import os
1312
from pathlib import Path
1413
import shutil
1514
from typing import List
1615

16+
from pythainer.sysutils import mkdir
17+
1718

1819
class DockerBuildCommand:
1920
"""
@@ -73,47 +74,52 @@ def get_str_for_dockerfile(
7374

7475
class CopyDockerBuildCommand(DockerBuildCommand):
7576
"""
76-
Represents a simple string command in a Dockerfile, such as a comment or other directive that
77-
does not involve complex logic or conditional behavior.
77+
Represents the command string to copy data from the host system to the docker container at build time.
7878
"""
7979

8080
def __init__(self, source_path:Path ,destination_path:Path) -> None:
8181
"""
82-
Initializes the StrDockerBuildCommand with a string.
82+
Initializes the CopyDockerBuildCommand with a a source and destination path.
8383
8484
Parameters:
85-
s (str): The string that represents this Dockerfile command.
85+
source_path (Path): Path of folder or file to copy to container
86+
destination_path (Path): Path to copy the file or folder to
8687
"""
8788
super().__init__()
88-
self._source_path = source_path
89+
self._source_path = source_path.resolve()
8990
self._destination_path = destination_path
9091

9192
# pylint: disable=arguments-differ
9293
def get_str_for_dockerfile(
9394
self,
94-
docker_file_Path: Path,
9595
*args,
9696
**kwargs,
9797
) -> str:
9898
"""
99-
Returns the string that was initialized at the creation of the object.
99+
Generates a Dockerfile string to move files and folders.
100100
101101
Returns:
102-
str: The command string.
102+
str: A Dockerfile command string for moving files and folders.
103103
"""
104104

105105
data_path = Path("/tmp/pythainer/docker/data")
106+
resulting_path = data_path / self._source_path.relative_to("/")
107+
relative_path = Path("data") / self._source_path.relative_to("/")
108+
mkdir(data_path)
109+
110+
print(data_path)
106111

107-
if os.path.isfile(self._source_path):
108-
shutil.copyfile(self._source_path, data_path / self._source_path)
109-
elif os.path.isdir(self._source_path):
110-
shutil.copytree(self._source_path, data_path / self._source_path,dirs_exist_ok=True)
112+
if self._source_path.is_file():
113+
mkdir(resulting_path.parent)
114+
shutil.copyfile(self._source_path, resulting_path)
115+
elif self._source_path.is_dir():
116+
shutil.copytree(self._source_path, resulting_path,dirs_exist_ok=True)
111117
else:
112118
raise FileExistsError(f'{self._source_path} is not a valid target to copy into the docker container')
113119

114120

115121

116-
cmd = f"COPY --chown=${{USER_NAME}} {self._source_path} {self._destination_path}"
122+
cmd = f"COPY --chown=${{USER_NAME}} {relative_path} {self._destination_path}"
117123

118124
return cmd
119125

0 commit comments

Comments
 (0)