Loading [Contrib]/a11y/accessibility-menu.js
Skip to content

sync

plantdb.commons.sync Link

This module provides a synchronization mechanism for PlantDB.

FSDBSync Link

FSDBSync(source, target)

Class for sync between two FSDB databases.

It checks for validity of both source and target by checking that:

  • there is a marker file in the DB path root
  • the DB is not busy by checking for the lock file in the DB path root.

It locks the two databases during the sync. The sync is done using rsync as a subprocess

Attributes:

Name Type Description
source_str str

Source path

target_str str

Target path

source dict

Source path description

target dict

Target path description

Class constructor.

Parameters:

Name Type Description Default
source str

Source database path (remote or local)

required
target str

Target database path (remote or local)

required
Source code in plantdb/commons/sync.py
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def __init__(self, source, target):
    """Class constructor.

    Parameters
    ----------
    source : str
        Source database path (remote or local)
    target : str
        Target database path (remote or local)
    """
    self.source_str = source
    self.target_str = target
    self.source = _fmt_path(source)
    self.target = _fmt_path(target)

lock Link

lock()

Lock the source and target DB before sync.

Source code in plantdb/commons/sync.py
89
90
91
92
93
94
95
def lock(self):
    """Lock the source and target DB before sync."""
    for x in [self.source, self.target]:
        if x["type"] == "local":
            _lock_local(x)
        elif x["type"] == "remove":
            _lock_remote(x)

sync Link

sync()

Sync the two DBs.

Source code in plantdb/commons/sync.py
 97
 98
 99
100
101
def sync(self):
    """Sync the two DBs."""
    self.lock()
    subprocess.run(["rsync", "-av", self.source_str, self.target_str])
    self.unlock()

unlock Link

unlock()

Unlock the source and target DB after sync.

Source code in plantdb/commons/sync.py
81
82
83
84
85
86
87
def unlock(self):
    """Unlock the source and target DB after sync."""
    for x in [self.source, self.target]:
        if x["type"] == "local":
            _unlock_local(x)
        elif x["type"] == "remove":
            _unlock_remote(x)