Q 3i#hSrSSKrSSKrSSKJr SSKJrJrJrJ r SSK J r SSK J r "SS5r g) z Directory Sync Engine - Unidirectional Mirror Synchronization Mirrors source directory to destination using mtime+size comparison N)Path)OptionalCallableDictAny)datetime)loggerc\rSrSrSrS\S\4SjrSS\\S\ \\ 44S jjr S \ S\ \ \ 44S jr S \ S \ S\4SjrS \ S \ 4SjrS\ \ \ 4S\4SjrS \ 4SjrSrg) DirectorySynca Unidirectional directory synchronization engine Mirrors source -> destination: - Copies new/modified files (based on mtime + size) - Deletes files from destination that don't exist in source - Preserves directory structure - Handles network paths (e.g., Z:\) source destinationcd[U5Ul[U5UlURR5(d[ SU35eURR 5(d[ SU35eURR SSS9 [R"SUSU35 g)z Initialize sync engine Args: source: Source directory path (can be network path) destination: Destination directory path (can be network path) zSource path does not exist: z Source path is not a directory: Tparentsexist_okzDirectorySync initialized: z -> N) rr rexists ValueErroris_dirmkdirr info)selfr rs /c:\PYTHON\Scheduler\modules\sync\sync_engine.py__init__DirectorySync.__init__s6l  ,{{!!##;F8DE E{{!!##?xHI I td; 1&k]KLNprogress_callbackreturnc 6SSSS/S.nU(a U"SSSSS.5 URUR5n[U5US'[R"S[U5S35 U(aU"S S[U5SS.5 [ UR 55HunupVURU- nURXg5(aCURXg5 US ==S - ss'US ==UR5R- ss'U(a$U"S US -[U5[U5S.5 MM U(a U"SSSSS.5 UR!U5n XS'[R"SUS SUSS35 U$![a>nS USU3n [R"U 5 USRU 5 SnAGM1SnAff=f![a5nSU3n [R""U 5 USRU 5 eSnAff=f)a Perform synchronization Args: progress_callback: Optional callback for progress updates Called with dict: {'phase': str, 'current': int, 'total': int, 'file': str} Returns: Dict with statistics: { 'files_scanned': int, 'files_copied': int, 'files_deleted': int, 'bytes_total': int, 'errors': List[str] } r) files_scanned files_copied files_deleted bytes_totalerrorsscanning)phasecurrenttotalfiler zScanned z files in sourcesyncingr!r#zError syncing : r$Ncleaningr"zSync completed: z copied, z deletedzCritical sync error: )_scan_directoryr lenr r enumerateitemsr _needs_sync _copy_filestatst_sizestr Exceptionerrorappend_cleanup_destination exception) rrstats source_filesidxrel_path source_file dest_filee error_msg deleted_counts rsyncDirectorySync.sync/s%&  1  !J1qZ\"]^// >!#'#3#3I#>-1* -$_5!vRs'CD !  LL4YKr!E F  s@'BA B BA=7B=BB B1B,,B1rArBc`UR5(dgUR5nUR5nURUR:wa$[R"SUR 35 gg![ [4a&n[R"SUSU35 SnAgSnAff=f)a0 Check if file needs to be synced using size comparison only Note: mtime comparison disabled because WebDAV/network drives don't preserve timestamps correctly with shutil.copy2() Args: source_file: Source file path dest_file: Destination file path Returns: True if file needs to be copied TzSize mismatch: FzCannot compare r-N) rr5r6r debugnamerNrOrP)rrArB source_stat dest_statrCs rr3DirectorySync._needs_syncs!! %**,K!(I""i&7&77 {/?/?.@AB)  NN_[MA3? @ sAA77B-B((B-c :URRSSS9 [R"X5 [R "SUR 35 g![[[R4a%n[R"SUSUSU35 eSnAff=f)z Copy file from source to destination, preserving metadata Args: source_file: Source file path dest_file: Destination file path TrzCopied: zFailed to copy z to r-N) parentrshutilcopy2r rUrVrNrOErrorr9)rrArBrCs rr4DirectorySync._copy_files     " "4$ " ? LL 0 LL8K$4$4#56 7&,,7  LL?;-tI;bL M  sAAB5 BBr>cSnURUR5nUHHnXA;dM URU- nUR5 [R"SU35 US- nMJ URUR5 U$![ [ 4a'n[R"SUSU35 SnAMSnAff=f![a$n[R"SU35 SnAU$SnAff=f)z Delete files from destination that don't exist in source Args: source_files: Dict of relative paths from source Returns: Number of files deleted rz Deleted: r,zFailed to delete r-NzError during cleanup: ) r/runlinkr rUrNrOr9_cleanup_empty_dirsr8)rr>rE dest_filesr@rBrCs rr;"DirectorySync._cleanup_destinations  7--d.>.>?J'/ $ 0 08 ;IK!((* y %;<%* '  $ $T%5%5 6 $_5K '8 2aS%IJJK  7 LL1!5 6 6 7sE#CC.B )C CB<6C<CC C2C--C2c[R"[U5SS9Hbup#n[U5nXQ:XaM[ UR 55(d+UR 5 [R"SU35 MbMd g![[4a Mzf=f![a#n[R"SU35 SnAgSnAff=f)zY Remove empty directories from destination Args: directory: Root directory to clean F)topdownzRemoved empty directory: z"Error cleaning empty directories: N) oswalkr7ranyiterdirrmdirr rUrNrOr8rP)rrHdirpathdirnames filenamesdir_pathrCs rrb!DirectorySync._cleanup_empty_dirss E02IPU0V,9=(x//122 ( '@ %KL31W 1 E NN?sC D D Es;6BABBBBBB C (CC )rr )N)__name__ __module__ __qualname____firstlineno____doc__r7rrrrrrFrr/boolr3r4intr;rb__static_attributes__rrr r sMsMM,Mhx&8MDcNM^$tTz2B6!t!!!Fdt*!dDj1A!c!FETErr )rurgr\pathlibrtypingrrrrrlogurur r ryrrr}s/  00EEr