Skip to content

LocalSyncHandler

LocalSyncHandler

Bases: FileSystemEventHandler

Sync the files to disk when they are created, modified, moved or deleted

Source code in Agent/utils/storage/local_sync_handler.py
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class LocalSyncHandler(FileSystemEventHandler):
    """
    Sync the files to disk when they are created, modified, moved or deleted
    """

    def __init__(self, src_path: str, dest_path: str, sshpass: str):
        """

        Args:
            src_path (str): The source path to sync
            dest_path (str): The destination path to sync
            sshpass (str): The password to ssh
        """
        super().__init__()
        self.src_path = src_path
        self.dest_path = dest_path
        self.sshpass = sshpass

    def on_any_event(self, event):
        """
        Sync the files to disk when they are created, modified, moved or deleted
        Args:
            event:

        Returns:

        """
        if event.is_directory:
            return None
        else:
            if self.sshpass:
                subprocess.call(
                    [
                        "sshpass",
                        "-p",
                        self.sshpass,
                        "rsync",
                        "-avz",
                        "--delete",
                        self.src_path,
                        self.dest_path,
                    ]
                )
            else:
                # wer can set up the authentication first, then we can use the rsync command
                subprocess.call(
                    ["rsync", "-avz", "--delete", self.src_path, self.dest_path]
                )

__init__(src_path, dest_path, sshpass)

Parameters:

Name Type Description Default
src_path str

The source path to sync

required
dest_path str

The destination path to sync

required
sshpass str

The password to ssh

required
Source code in Agent/utils/storage/local_sync_handler.py
15
16
17
18
19
20
21
22
23
24
25
26
def __init__(self, src_path: str, dest_path: str, sshpass: str):
    """

    Args:
        src_path (str): The source path to sync
        dest_path (str): The destination path to sync
        sshpass (str): The password to ssh
    """
    super().__init__()
    self.src_path = src_path
    self.dest_path = dest_path
    self.sshpass = sshpass

on_any_event(event)

Sync the files to disk when they are created, modified, moved or deleted Args: event:

Returns:

Source code in Agent/utils/storage/local_sync_handler.py
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def on_any_event(self, event):
    """
    Sync the files to disk when they are created, modified, moved or deleted
    Args:
        event:

    Returns:

    """
    if event.is_directory:
        return None
    else:
        if self.sshpass:
            subprocess.call(
                [
                    "sshpass",
                    "-p",
                    self.sshpass,
                    "rsync",
                    "-avz",
                    "--delete",
                    self.src_path,
                    self.dest_path,
                ]
            )
        else:
            # wer can set up the authentication first, then we can use the rsync command
            subprocess.call(
                ["rsync", "-avz", "--delete", self.src_path, self.dest_path]
            )