Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
qim3d
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
QIM
Tools
qim3d
Merge requests
!15
Directories check
Code
Review changes
Check out branch
Open in Workspace
Download
Patches
Plain diff
Expand sidebar
Merged
Directories check
directories_check
into
main
Overview
0
Commits
5
Pipelines
0
Changes
1
Merged
Directories check
fima
requested to merge
directories_check
into
main
Sep 25, 2023
Overview
0
Commits
5
Pipelines
0
Changes
1
Function for checking the difference between directories
0
0
Merge request reports
Viewing commit
92d7327b
Prev
Next
Show latest version
1 file
+
61
−
5
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
92d7327b
Docstrings
· 92d7327b
Felipe Delestro Matos
authored
Sep 25, 2023
qim3d/io/sync.py
+
61
−
5
View file @ 92d7327b
Edit in single-file editor
Open in Web IDE
Show full file
@@ -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