Skip to content
Snippets Groups Projects

Directories check

1 file
+ 61
5
Compare changes
  • Side-by-side
  • Inline
+ 61
5
@@ -7,6 +7,8 @@ from pathlib import Path
class Sync:
"""Class for dataset synchronization tasks"""
def __init__(self):
# Checks if rsync is available
if not self._check_rsync():
@@ -27,7 +29,23 @@ class Sync:
return False
def check_destination(self, source, destination, checksum=False, verbose=True):
"""Check if all files from 'source' are in 'destination'"""
"""Check if all files from 'source' are in 'destination'
This function compares the files in the 'source' directory to those in
the 'destination' directory and reports any differences or missing files.
Args:
source (str or Path): The source directory path.
destination (str or Path): The destination directory path.
checksum (bool, optional): If True, use checksums to compare files (slower but more accurate).
Default is False.
verbose (bool, optional): If True, display a list of differing or missing files in the log.
Default is True.
Returns:
list: A list of differing or missing file paths in the destination directory.
"""
source = Path(source)
destination = Path(destination)
@@ -63,10 +81,29 @@ class Sync:
return diff_files
def compare_dirs(self, source, destination, checksum=False, verbose=True):
"""Checks with source and destination are synchronized"""
# source = Path(source)
# destination = Path(destination)
"""Checks whether 'source' and 'destination' directories are synchronized.
This function compares the contents of two directories
('source' and 'destination') and reports any differences.
It checks for files that exist in one directory but not the other and
files that are present in both but not equal.
If no differences are found between the directories,
it logs a message indicating that they are synchronized.
If differences are found, it logs detailed information about the differing files.
Args:
source (str or Path): The source directory path.
destination (str or Path): The destination directory path.
checksum (bool, optional): If True, use checksums to compare files (slower but more accurate).
Default is False.
verbose (bool, optional): If True, display information about the comparison in the log.
Default is True.
Returns:
None: This function does not return a value.
"""
if verbose:
s_files, s_dirs = self.count_files_and_dirs(source)
d_files, d_dirs = self.count_files_and_dirs(destination)
@@ -132,7 +169,26 @@ class Sync:
return
def count_files_and_dirs(self, path, verbose=True):
"""Count the number of files and directories in the given path"""
"""Count the number of files and directories in the given path.
This function recursively counts the number of files and
directories in the specified directory 'path'.
If 'verbose' is True, the function logs the total count
of files and directories in the specified path.
Args:
path (str or Path): The directory path to count files and directories in.
verbose (bool, optional): If True, display the total count in the log.
Default is True.
Returns:
tuple: A tuple containing two values:
- The count of files in the directory and its subdirectories.
- The count of directories in the directory and its subdirectories.
"""
path = Path(path)
files = 0
dirs = 0
Loading