;anixdZddlmZddlmZddlmZmZmZmZddl m Z ddl m Z ddl mZGdd Zd S) zp Sync Module - Integration with Automation Daemon Manages sync operations, scheduling, and database integration )Path)datetime)DictAnyOptionalCallable)logger)Database) DirectorySyncc eZdZdZdefdZ d dedeedeede e e ffd Z ded ede e e ffd Z d ZdS) SyncModulezi Sync module for unified daemon Integrates DirectorySync with database and scheduling system dbc<||_tjddS)zm Initialize sync module Args: db: Database instance for CRUD operations zSyncModule initializedN)rr info)selfrs /C:\PYTHON\Scheduler\modules\sync\sync_module.py__init__zSyncModule.__init__s" ,-----N profile_id schedule_idprogress_callbackreturnc |j|}|sd|d}tj|d|dS|dsd|d}tj|d|dS|j|r d|d}tj|d|dd St j}|j|d | }tj d |d |d|d g}| dr%d|d dD}t| dd} t|d|d|| } | |} | dr3d} t| dd} tjd|dnd} d} tj d|dt j}|j|| || d | d!| d"| d#| $d||| d | d!| d"| d#||z d%d&S#t$$ri}t'|}tjd|d'||j|d(t j|)d|||d*cYd}~Sd}~wwxYw)+aS Execute a sync operation Args: profile_id: Sync profile ID schedule_id: Optional schedule ID (when triggered by scheduler) progress_callback: Optional callback for progress updates Returns: Dict with operation results (success, operation_id, stats, error) z Sync profile z not foundF)successerrorenabledz is disabledz1 is already running - skipping to prevent overlapT)rrskippedrunning)rstatus start_timezStarting sync operation z for profile z: nameexclude_patternsc^g|]*}||+S)strip).0ps r z+SyncModule.execute_sync..Ps2#l#l#l!bcbibibkbk#lAGGII#l#l#lr protect_excluded source_pathdestination_path)source destinationr"r*)rerrorscompleted_with_errorsz error(s) occurredzSync operation z completed with errors completedNz completed successfully files_scanned files_copied files_deleted bytes_total) operation_idrend_timer2r3r4r5 error_message)r2r3r4r5duration_seconds)rr6rstatsz failed: failed)r6rr7r8)rr6rr)rget_sync_profiler rwarninghas_running_sync_operationrnowcreate_sync_operationrgetsplitboolr synclenupdate_sync_operation total_seconds Exceptionstr)rrrrprofile error_msgr r6r"r* sync_enginer:rr8r7es r execute_synczSyncModule.execute_syncs$'**:66 :> >>>I L # # #$y99 9y! :@ @@@I N9 % % %$y99 9 7 - -j 9 9 Ke eeeI N9 % % %$yTJJ J\^^ w44!!5   i|ii*iiX_`fXgiijjjJ ! {{-.. m#l#lw?Q7R7X7XY]7^7^#l#l#l  $GKK0BE$J$JKK (}-#$67!1!1 K $$7H$IIEyy"" U0#&uX#7#7 K K K UUUUVVVV$ $  SlSSSTTT |~~H G ) ))!#O4">2#O4!-0+ *    ,(%*?%;$).$9%*?%;#(#7)1J)>(M(M(O(O       AI LM<MM)MM N N N G ) ))!' *   ! ,("        s 1E>I00 K#:AKK#K# target_idchtjd|d||||}|S)a" Execute scheduled sync operation Called by daemon when a schedule triggers Args: schedule_id: Schedule ID that triggered target_id: Sync profile ID (from schedule.target_id) Returns: Dict with execution results z Schedule z triggered for sync profile )rr)r rrN)rrrOresults r schedule_itemzSyncModule.schedule_itemsD  T TTTTUUU""i["QQ rc.tjddS)zCleanup module resourceszSyncModule cleanup completedN)r r)rs rcleanupzSyncModule.cleanups 233333r)NN)__name__ __module__ __qualname____doc__r rintrrrrIrrNrRrTr$rrr r s .8....&*04 wwwc]w$H- w c3h wwwwrc3h&44444rr N)rXpathlibrrtypingrrrrlogurur core.databaser modules.sync.sync_enginer r r$rrr_s 000000000000""""""222222^4^4^4^4^4^4^4^4^4^4r