folder_syncv package¶
Submodules¶
folder_syncv.syncv module¶
Provides functions to sync folder to replica.
- folder_syncv.syncv.is_file_in_other(file_to_check: Path, source: Path, destination: Path) bool[source]¶
Check if file_to_check is in destination folder.
- Parameters:
file_to_check (pathlib.Path) – path of the file to check from the source folder
source (pathlib.Path) – path of the source folder
destination (pathlib.Path) – path of the destination folder
- Returns:
True if the file is found in the destination False otherwise
- Return type:
- Raises:
ExpectedFileIsAFolder custom exception if the file is found but it's a folder –
- folder_syncv.syncv.is_file_in_other_as_folder(file_to_check: Path, source: Path, destination: Path) bool[source]¶
Check if file_to_check is in destination folder but it’s a folder.
- Parameters:
file_to_check (pathlib.Path) – path of the file to check from the source folder
source (pathlib.Path) – path of the source folder
destination (pathlib.Path) – path of the destination folder
- Returns:
True if the file is found in the destination and is a folder. False otherwise
- Return type:
- folder_syncv.syncv.is_file_in_other_modified(file_to_check: Path, source: Path, destination: Path) bool[source]¶
Check if file_to_check is in destination folder and it’s the same file. Given there is a file with the same name in the destination folder (same relative path) assume if modification times are the same the files are the same. If the modifications time are different compare the files’ content using md5.
- Parameters:
file_to_check (pathlib.Path) – path of the file to check from the source folder
source (pathlib.Path) – path of the source folder
destination (pathlib.Path) – path of the destination folder
- Returns:
False of the file is found in the destination at the same relative path and either the modification times are the same or the md5 hash of the contents are the same. True otherwise
- Return type:
- Raises:
FileNotFoundError if the file is not found in the destination folder –
- folder_syncv.syncv.is_folder_in_other_as_file(folder_to_check: Path, source: Path, destination: Path) bool[source]¶
Return true if the folder_to_check path is in destination but it’s a file not a folder.
- Parameters:
folder_to_check (pathlib.Path) – the folder to search for in destination (relative path must match)
source (pathlib.Path) – path of the soruce folder
destination (pathlib.Path) – path of the destination
- Returns:
True if the folder searched is in the destination folder but it’s a file. False otherwise.
- Return type:
- folder_syncv.syncv.is_folder_in_other_as_folder(folder_to_check: Path, source: Path, destination: Path) bool[source]¶
Return true if the folder_to_check path is in destination and is a folder.
- Parameters:
folder_to_check (pathlib.Path) – the folder to search for in destination (relative path must match)
source (pathlib.Path) – path of the soruce folder
destination (pathlib.Path) – path of the destination
- Returns:
True if the folder searched is in the destination folder and is a file. False otherwise.
- Return type:
- folder_syncv.syncv.setup_logging(loglevel: Literal['debug', 'info', 'warn', 'error', 'critical'], logfile: str | Path) None[source]¶
Setup logging
- Parameters:
loglevel (logging._Level) – minimum loglevel for emitting messages
- Returns:
None
- folder_syncv.syncv.sync_folder(source: Path, replica: Path, syncinterval: int, logfile: Path, loglevel: Literal['debug', 'info', 'warn', 'error', 'critical']) None[source]¶
Synchronizes SOURCE folder to REPLICA folder.
- Parameters:
source (pathlib.Path) – path of the source folder
replica (pathlib.Path) – path of the target folder
syncinterval (int) – period with which to repeat the sync in seconds
logfile (pathlib.Path) – path of the logfile
loglevel (LOGLEVEL) – level of the log
- Returns:
None
- folder_syncv.syncv.sync_replica_to_source(source: Path, replica: Path) tuple[int, int][source]¶
Remove files and folders from replica which are not in source. :param source: path of the source folder :type source: pathlib.Path :param replica: path of the target folder :type replica: pathlib.Path
- folder_syncv.syncv.sync_source_to_replica(source: Path, replica: Path) tuple[int, int, int, int, int, int][source]¶
Sync source contents to replica. :param source: path of the source folder :type source: pathlib.Path :param replica: path of the target folder :type replica: pathlib.Path
- folder_syncv.syncv.validate_replica(path: Path) bool[source]¶
Validate replica folder. If it doesn’t exist, create it. If it exists but it’s not a folder raise SystemExit. If it can’t create it raise PermissionError
- Parameters:
path (pathlib.Path) – replica folder path
- Returns:
True if path exists and is a folder or if it doesn’t exist but it created it successfuelly.
- Return type:
- Raises:
SystemExit – path is not a folder
SystemExit – could not create replica folder
- folder_syncv.syncv.validate_source(path: Path) bool[source]¶
Validate source folder
- Parameters:
path (pathlib.Path) – source folder path
- Returns:
True if path exists and is a folder
- Return type:
- Raises:
SystemExit – path does not exist
SystemExit – path is not a folder