25
25
from abc import ABC , abstractmethod
26
26
from collections .abc import Iterable
27
27
from ipaddress import IPv4Interface , IPv6Interface
28
- from pathlib import Path , PurePath
28
+ from pathlib import Path , PurePath , PurePosixPath
29
29
from typing import Union
30
30
31
31
from framework .config import Architecture , NodeConfiguration , NodeInfo
38
38
)
39
39
from framework .remote_session .remote_session import CommandResult
40
40
from framework .settings import SETTINGS
41
- from framework .utils import MesonArgs
41
+ from framework .utils import MesonArgs , TarCompressionFormat
42
42
43
43
from .cpu import LogicalCore
44
44
from .port import Port
@@ -203,6 +203,95 @@ def copy_to(self, source_file: str | Path, destination_dir: str | PurePath) -> N
203
203
will be saved.
204
204
"""
205
205
206
+ @abstractmethod
207
+ def copy_dir_from (
208
+ self ,
209
+ source_dir : str | PurePath ,
210
+ destination_dir : str | Path ,
211
+ compress_format : TarCompressionFormat = TarCompressionFormat .none ,
212
+ exclude : str | list [str ] | None = None ,
213
+ ) -> None :
214
+ """Copy a directory from the remote node to the local filesystem.
215
+
216
+ Copy `source_dir` from the remote node associated with this remote session to
217
+ `destination_dir` on the local filesystem. The new local directory will be created
218
+ at `destination_dir` path.
219
+
220
+ Example:
221
+ source_dir = '/remote/path/to/source'
222
+ destination_dir = '/local/path/to/destination'
223
+ compress_format = TarCompressionFormat.xz
224
+
225
+ The method will:
226
+ 1. Create a tarball from `source_dir`, resulting in:
227
+ '/remote/path/to/source.tar.xz',
228
+ 2. Copy '/remote/path/to/source.tar.xz' to
229
+ '/local/path/to/destination/source.tar.xz',
230
+ 3. Extract the contents of the tarball, resulting in:
231
+ '/local/path/to/destination/source/',
232
+ 4. Remove the tarball after extraction
233
+ ('/local/path/to/destination/source.tar.xz').
234
+
235
+ Final Path Structure:
236
+ '/local/path/to/destination/source/'
237
+
238
+ Args:
239
+ source_dir: The directory on the remote node.
240
+ destination_dir: The directory path on the local filesystem.
241
+ compress_format: The compression format to use. Defaults to no compression.
242
+ exclude: Patterns for files or directories to exclude from the tarball.
243
+ These patterns are used with `tar`'s `--exclude` option.
244
+ """
245
+
246
+ @abstractmethod
247
+ def copy_dir_to (
248
+ self ,
249
+ source_dir : str | Path ,
250
+ destination_dir : str | PurePath ,
251
+ compress_format : TarCompressionFormat = TarCompressionFormat .none ,
252
+ exclude : str | list [str ] | None = None ,
253
+ ) -> None :
254
+ """Copy a directory from the local filesystem to the remote node.
255
+
256
+ Copy `source_dir` from the local filesystem to `destination_dir` on the remote node
257
+ associated with this remote session. The new remote directory will be created at
258
+ `destination_dir` path.
259
+
260
+ Example:
261
+ source_dir = '/local/path/to/source'
262
+ destination_dir = '/remote/path/to/destination'
263
+ compress_format = TarCompressionFormat.xz
264
+
265
+ The method will:
266
+ 1. Create a tarball from `source_dir`, resulting in:
267
+ '/local/path/to/source.tar.xz',
268
+ 2. Copy '/local/path/to/source.tar.xz' to
269
+ '/remote/path/to/destination/source.tar.xz',
270
+ 3. Extract the contents of the tarball, resulting in:
271
+ '/remote/path/to/destination/source/',
272
+ 4. Remove the tarball after extraction
273
+ ('/remote/path/to/destination/source.tar.xz').
274
+
275
+ Final Path Structure:
276
+ '/remote/path/to/destination/source/'
277
+
278
+ Args:
279
+ source_dir: The directory on the local filesystem.
280
+ destination_dir: The directory path on the remote node.
281
+ compress_format: The compression format to use. Defaults to no compression.
282
+ exclude: Patterns for files or directories to exclude from the tarball.
283
+ These patterns are used with `fnmatch.fnmatch` to filter out files.
284
+ """
285
+
286
+ @abstractmethod
287
+ def remove_remote_file (self , remote_file_path : str | PurePath , force : bool = True ) -> None :
288
+ """Remove remote file, by default remove forcefully.
289
+
290
+ Args:
291
+ remote_file_path: The file path to remove.
292
+ force: If :data:`True`, ignore all warnings and try to remove at all costs.
293
+ """
294
+
206
295
@abstractmethod
207
296
def remove_remote_dir (
208
297
self ,
@@ -213,11 +302,34 @@ def remove_remote_dir(
213
302
"""Remove remote directory, by default remove recursively and forcefully.
214
303
215
304
Args:
216
- remote_dir_path: The path of the directory to remove.
305
+ remote_dir_path: The directory path to remove.
217
306
recursive: If :data:`True`, also remove all contents inside the directory.
218
307
force: If :data:`True`, ignore all warnings and try to remove at all costs.
219
308
"""
220
309
310
+ @abstractmethod
311
+ def create_remote_tarball (
312
+ self ,
313
+ remote_dir_path : str | PurePath ,
314
+ compress_format : TarCompressionFormat = TarCompressionFormat .none ,
315
+ exclude : str | list [str ] | None = None ,
316
+ ) -> PurePosixPath :
317
+ """Create a tarball from the contents of the specified remote directory.
318
+
319
+ This method creates a tarball containing all files and directories
320
+ within `remote_dir_path`. The tarball will be saved in the directory of
321
+ `remote_dir_path` and will be named based on `remote_dir_path`.
322
+
323
+ Args:
324
+ remote_dir_path: The directory path on the remote node.
325
+ compress_format: The compression format to use. Defaults to no compression.
326
+ exclude: Patterns for files or directories to exclude from the tarball.
327
+ These patterns are used with `tar`'s `--exclude` option.
328
+
329
+ Returns:
330
+ The path to the created tarball on the remote node.
331
+ """
332
+
221
333
@abstractmethod
222
334
def extract_remote_tarball (
223
335
self ,
@@ -227,7 +339,7 @@ def extract_remote_tarball(
227
339
"""Extract remote tarball in its remote directory.
228
340
229
341
Args:
230
- remote_tarball_path: The path of the tarball on the remote node.
342
+ remote_tarball_path: The tarball path on the remote node.
231
343
expected_dir: If non-empty, check whether `expected_dir` exists after extracting
232
344
the archive.
233
345
"""
0 commit comments