K i)"dZddlmZddlZddlZddlZddlmZddlm Z m Z m Z m Z m Z mZmZmZmZmZmZmZmZmZddlmZmZmZmZddlmZddlmZerdd lm Z m!Z!ejDe#Z$Gd d eZ%Gd d e%Z&GddeZ'y)u:module: watchdog.observers.inotify :synopsis: ``inotify(7)`` based emitter implementation. :author: Sebastien Martini :author: Luke McCarthy :author: yesudeep@google.com (Yesudeep Mangalapilly) :author: Tim Cuthbertson :author: contact@tiger-222.fr (Mickaël Schoentgen) :platforms: Linux 2.6.13+. .. ADMONITION:: About system requirements Recommended minimum kernel version: 2.6.25. Quote from the inotify(7) man page: "Inotify was merged into the 2.6.13 Linux kernel. The required library interfaces were added to glibc in version 2.4. (IN_DONT_FOLLOW, IN_MASK_ADD, and IN_ONLYDIR were only added in version 2.5.)" Therefore, you must ensure the system is running at least these versions appropriate libraries and the kernel. .. ADMONITION:: About recursiveness, event order, and event coalescing Quote from the inotify(7) man page: If successive output inotify events produced on the inotify file descriptor are identical (same wd, mask, cookie, and name) then they are coalesced into a single event if the older event has not yet been read (but see BUGS). The events returned by reading from an inotify file descriptor form an ordered queue. Thus, for example, it is guaranteed that when renaming from one directory to another, events will be produced in the correct order on the inotify file descriptor. ... Inotify monitoring of directories is not recursive: to monitor subdirectories under a directory, additional watches must be created. This emitter implementation therefore automatically adds watches for sub-directories if running in recursive mode. Some extremely useful articles and documentation: .. _inotify FAQ: http://inotify.aiken.cz/?section=inotify&page=faq&lang=en .. _intro to inotify: http://www.linuxjournal.com/article/8478 ) annotationsN) TYPE_CHECKING)DirCreatedEventDirDeletedEventDirModifiedEvent DirMovedEventFileClosedEventFileClosedNoWriteEventFileCreatedEventFileDeletedEventFileModifiedEventFileMovedEventFileOpenedEventFileSystemEventgenerate_sub_created_eventsgenerate_sub_moved_events)DEFAULT_EMITTER_TIMEOUTDEFAULT_OBSERVER_TIMEOUT BaseObserver EventEmitter) InotifyBuffer)InotifyConstants) EventQueue ObservedWatchcleZdZdZedd d fdZd dZd dZdddd Zdd Z dd Z xZ S)InotifyEmittera/inotify(7)-based event emitter. :param event_queue: The event queue to fill with events. :param watch: A watch object representing the directory to monitor. :type watch: :class:`watchdog.observers.api.ObservedWatch` :param timeout: Read events blocking timeout (in seconds). :type timeout: ``float`` :param event_filter: Collection of event types to emit, or None for no filtering (default). :type event_filter: Iterable[:class:`watchdog.events.FileSystemEvent`] | None Ntimeout event_filterclt|||||tj|_d|_y)Nr)super__init__ threadingLock_lock_inotify)self event_queuewatchrr __class__s `/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/watchdog/observers/inotify.pyr"zInotifyEmitter.__init__hs0 eW<X^^% .2 ctj|jj}|j }t ||jj ||_y)N) recursive event_mask)osfsencoder)pathget_event_mask_from_filterr is_recursiver&)r'r2r/s r+on_thread_startzInotifyEmitter.on_thread_starttsA{{4::??+446 %ddjj6M6MZde r,c`|jr"|jjd|_yy)N)r&close)r's r+on_thread_stopzInotifyEmitter.on_thread_stopys% == MM   ! DM r,F full_eventsc` |jtjdy|j5|jtjd dddy|jj }| dddyt |t r'|\}}|j|j}|j|j}|jrtnt}|j||||jttjj!||jttjj!||jr8|j"j$r"t'||D]} |j|  dddy|j|j}|j(r|r1|jrtnt}|j|d|n/|jrt*nt,}|j|||jttjj!||jr|j"j$rt/|D]} |j| n|j0s |j2r1|jrtnt4}|j||n|j6s|j8rj|sh|jrt:nt<}|j|||jttjj!|n|j8rk|ri|jrtnt}|j||d|jttjj!|n|j>rh|jrt*nt,}|j|||jttjj!|n%|j@rY||j"jk(r@|jrt:nt<}|j|||jCn|js|jDrtF}|j||n|jHrUtJ}|j|||jttjj!|n)|jLrtN}|j||dddy#1swYyxYw)Nz@InotifyEmitter.queue_events() called when the thread is inactive)(r&loggererrorr% read_event isinstancetuple _decode_pathsrc_path is_directoryrr queue_eventrr0r2dirnamer)r4r is_moved_torr r is_attrib is_modifyr is_delete is_moved_fromrr is_createis_delete_selfstopis_openris_close_writer is_close_nowriter ) r'rr:event move_frommove_torC dest_pathclssub_moved_eventsub_created_events r+ queue_eventszInotifyEmitter.queue_events~s == LL[ \  ZZ? 4}}$ _`? 4? 4MM,,.E} ? 4? 4%'%*" 7,,Y-?-?@ --g.>.>? '0'='=m>  Xy!9:  !1"''//(2K!LM  !1"''//)2L!MN))djj.E.E+DXy+Y:((9:)? 4? 4,((8H  +0+=+=->C$$SX%67-2-?-?/EUC$$S]3  !1"''//(2K!LM%%$***A*A-H-R<)(():;<EOO*/*<*<&BS  X/U%8%8).););oAQ  X/  !1"''//(2K!LM$$','9'9m~  Xr!23  !1"''//(2K!LM).););oAQ  X/  !1"''//(2K!LM%%(djjoo*E).););oAQ  X/ ''==)C$$S]3)))C$$S]3$$%5bggooh6O%PQ++0C$$S]3? 4? 4? 4s#V$V$D/V$9O"V$$V-cxt|jjtr|St j |S)z>Decode path only if unicode string was passed to this emitter.)r@r)r2bytesr0fsdecode)r'r2s r+rBzInotifyEmitter._decode_paths'!$**//59tPr{{4?PPr,c|jytj}|jD]_}|tthvr|tj z}&|t thvr%|tj tjzz}Y|turX|tj tjztjztjztjzz}|tur%|tjtjzz}|tthvr|tj z} |t"ur|tjz}&|t$ur|tj&z}C|t(usM|tj*z}b|S)zCOptimization: Only include events we are filtering in inotify call.N) _event_filterrIN_DELETE_SELFrrIN_MOVErr IN_CREATEr IN_ATTRIB IN_MODIFYIN_CLOSE_WRITEr rr IN_DELETEr r IN_CLOSE_NOWRITErIN_OPEN)r'r/rVs r+r3z)InotifyEmitter.get_event_mask_from_filterso    %&44 %% 7C}n55.666 *:;;.669I9S9SSS (($,,&001&001'001'55 6 )).88;K;U;UUU *:;;.888 '.=== ...??? '.666 - 70r,) r(rr)rrfloatrz"list[type[FileSystemEvent]] | NonereturnNone)rirj)rrhr:boolrirj)r2 bytes | strrirl)riz int | None) __name__ __module__ __qualname____doc__rr"r5r8rYrBr3 __classcell__r*s@r+rrUsi.1;? 3 3 3  3 9 3  3f ! CHE4NQ r,rc*eZdZdZdddfdZxZS)InotifyFullEmitterzinotify(7)-based event emitter. By default this class produces move events even if they are not matched Such move events will have a ``None`` value for the unmatched part. T)eventsc(t|||y)Nr9)r!rY)r'rrur*s r+rYzInotifyFullEmitter.queue_eventss W&9r,)rrhrurkrirj)rmrnrorprYrqrrs@r+rtrts>B::r,rtc,eZdZdZedddfdZxZS)InotifyObserverzdObserver thread that schedules watching directories and dispatches calls to event handlers. F)rgenerate_full_eventscD|rtnt}t| ||y)N)r)rtrr!r")r'rryrVr*s r+r"zInotifyObserver.__init__s$8 n g.r,)rrhryrkrirj)rmrnrorprr"rqrrs@r+rxrxs,Dbg//r,rx)(rp __future__rloggingr0r#typingrwatchdog.eventsrrrrr r r r r rrrrrwatchdog.observers.apirrrr!watchdog.observers.inotify_bufferrwatchdog.observers.inotify_crrr getLoggerrmr=rrtrxr,r+rs~1f#   qp;9@   8 $T\Tn::/l/r,