Skip to content

fsdb_check

plantdb.commons.cli.fsdb_check Link

backup_file Link

backup_file(file)

Backup a file by creating a timestamped copy.

Parameters:

Name Type Description Default
file str or Path

The path to the file to backup.

required
Source code in plantdb/commons/cli/fsdb_check.py
59
60
61
62
63
64
65
66
67
68
69
def backup_file(file):
    """Backup a file by creating a timestamped copy.

    Parameters
    ----------
    file : str or pathlib.Path
        The path to the file to backup.
    """
    bak_fname = backup_filename(file)
    copy(file, bak_fname)
    return bak_fname

backup_filename Link

backup_filename(file)

Create a backup a filename by adding a timestamp.

Parameters:

Name Type Description Default
file str or Path

The path to the file to backup.

required

Examples:

>>> backup_filename("test/file.json")
PosixPath('test/file_230601_105815.json')
Source code in plantdb/commons/cli/fsdb_check.py
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
def backup_filename(file):
    """Create a backup a filename by adding a timestamp.

    Parameters
    ----------
    file : str or pathlib.Path
        The path to the file to backup.

    Examples
    --------
    >>> backup_filename("test/file.json")
    PosixPath('test/file_230601_105815.json')
    """
    file = Path(file)
    now = datetime.datetime.now()
    timestamp = now.strftime("%y%m%d_%H%M%S")
    fname = file.stem
    return file.with_stem(f"{fname}_{timestamp}")

same_jsons Link

same_jsons(file_a, file_b)

Test if two JSON files have the same content.

Source code in plantdb/commons/cli/fsdb_check.py
78
79
80
81
82
83
84
85
def same_jsons(file_a, file_b) -> bool:
    """Test if two JSON files have the same content."""
    # Basic check, maybe using a third-party lib like `deepdiff` could give more insight.
    file_a = Path(file_a)
    file_b = Path(file_b)
    json_a = _load_json(file_a)
    json_b = _load_json(file_b)
    return json_a == json_b