K ilcdZddlmZddlZddlZddlZddlZddlZddlZddl m Z m Z ddl m Z ddlmZddlmZmZddlmZmZmZdd lmZer dd l mZmZdd lmZdd lmZdd lmZddl m!Z!ejDejFdZ$dZ%Gdde Z&dZ'e e'e&Z(e(jSddee(jUdZ+iZ,e-e.e/efZ0ddZ1e+dd ddZ2ejfdddZ4dd dd!Z5dd"Z6d#d dd$Z7 dd&Z8dd'Z9e2e1d(d)d*+e1d,d-d.ejfd/0e1d1d2d3d4e:d56e1d7d8d9d:;e1de1d?d8d@>e1dAd8dB>e1dCd8dD>e1dEd8dF>g dgGddHZ;e2e1dId)dJ+e1d,d-d.ejfd/0e1dKddL0e1dMdNdOd8dPQgdRgGddSZ<e2e1dTd)d-dUVe1dWdXdYdZd)d[\e1d]d^d_d`dadb\e1dcddded8dfQe1dgd7d%d8dhQe1d1d2d3d4e:di6e1de1d?d8d@>e1dAd8dB>e1dCd8dD>e1dEd8dF>g ddjZ=e2e1dTd)d-dkVe1dldmdnddo\e1dWdXdYdZd)d[\e1d]d^d_d`dadb\e1dcdddedpd8dfqe1dgd7d%d8dhQe1d1d2d3d4e:di6e1drdsdtd8duQe1dvdwdxd8dyQe1dg ddzZ>e2e1dnd{|e1d}d~d)de1dddTddde1dWdXdYdZd)d[\e1d]d^d_d`dadb\e1dcdddedpd8dfqe1dgd7d%d8dhQe1d1d2d3d4e:di6e1dddd\e1de1ddde:d6e1ddde:d6e1ddd9ddqg ddZ?Gdde@ZAddZBddZCeDdk(rejeCyy)u:module: watchdog.watchmedo :author: yesudeep@google.com (Yesudeep Mangalapilly) :author: contact@tiger-222.fr (Mickaël Schoentgen) :synopsis: ``watchmedo`` shell script utility. ) annotationsN)ArgumentParserRawDescriptionHelpFormatter)StringIO)dedent) TYPE_CHECKINGAny)WatchdogShutdownError load_classplatform)VERSION_STRING) Namespace_SubParsersAction)Callable)FileSystemEventHandler) ObserverType) BaseObserver)leveltricksz python-pathc:eZdZdZdddfdZddZd dZxZS) HelpFormattera#A nicer help formatter. Help for arguments can be indented and contain new lines. It will be de-dented and arguments in the help will be separated by a blank line for better readability. Source: https://github.com/httpie/httpie/blob/2423f89/httpie/cli/argparser.py#L31 )max_help_positionc.||d<t||i|y)Nr)super__init__)selfrargskwargs __class__s X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/watchdog/watchmedo.pyrzHelpFormatter.__init__0s &7"# $)&)c4dt|jdS)N<>)type__name__)rs r!__repr__zHelpFormatter.__repr__5s4:&&'q))r"cZt|jdz}|jS)Nz )rstrip splitlines)rtextwidths r! _split_lineszHelpFormatter._split_lines8s&d|!!#f,  r")rr rintrr returnNone)r0str)r,r2r-r/r0 list[str])r' __module__ __qualname____doc__rr(r. __classcell__)r s@r!rr&s=>* *!r"ru,Copyright 2018-2024 Mickaël Schoentgen & contributors Copyright 2014-2018 Thomas Amland & contributors Copyright 2012-2014 Google, Inc. Copyright 2011-2012 Yesudeep Mangalapilly Licensed under the terms of the Apache license, version 2.0. Please see LICENSE in the source code for more information.)epilogformatter_classz --versionversion)actionr: top_command)destct||fS)z\Convenience function to properly format arguments to pass to the command decorator. )list) name_or_flagsrs r!argumentrANs   &&r")parent cmd_aliasescdfd }|S)a Decorator to define a new command in a sanity-preserving way. The function will be stored in the ``func`` variable when the parser parses arguments so that it can be called directly like so:: >>> args = cli.parse_args() >>> args.func(args) c|jjdd}t|jxsd} j |xsg|t }|t |<|j}|jddddd |jd d ddd D])\}}|j|i||j|+|S)N_-)aliases descriptionr9z-qz--quiet verbosity append_const)r=r;constz-vz --verbose)func) r'replacerr6 add_parserrcommand_parsersadd_mutually_exclusive_group add_argument set_defaults) rPnamedescparserverbosity_groupr@rrrCrBs r! decoratorzcommand..decoratords}}$$S#.dll(b)""41BPTfs"t & ==?$$T9;~eg$h$$T;[Q_gh$i%) + !M6 F   9& 9   T  * + r")rPrr0r)rrBrCr[s``` r!commandr]Us  r") separatorc$|j|S)zSplits a pathname specification separated by an OS-dependent separator. :param pathname_spec: The pathname specification. :param separator: (OS Dependent) `:` on Unix and `;` on Windows or user-specified. split) pathname_specr^s r! path_splitrcts   y ))r")indexc^|dddD]"}tjj||$y)zAdds specified paths at specified index into the sys.path list. :param paths: A list of paths to add to the sys.path :param index: (Default 0) The index in the sys.path list where the paths will be added. NrM)syspathinsert) pathnamesrdpathnames r!add_to_sys_pathrks-ddO) x()r"cddl}t|d5}|j|jcdddS#1swYyxYw)zLoads the YAML configuration from the specified file. :param tricks_file_path: The path to the tricks configuration file. :returns: A dictionary of configuration information. rNrb)yamlopen safe_loadread)tricks_file_pathnamernfs r! load_configrts; "D )(Q~~affh'(((s :A;c^|j|}|j|}|dgk(rg}||fS)z^Parses pattern argument specs and returns a two-tuple of (patterns, ignore_patterns). rHr`) patterns_specignore_patterns_specr^patternsignore_patternss r!parse_patternsr{s> ""9-H*00;O2$ _ $$r" recursivect|D]}|j||||j tjd#t $r|j YnwxYw|jy)agSingle observer thread with a scheduled path and event handler. :param observer: The observer thread. :param event_handler: Event handler which will be called in response to file system events. :param pathnames: A list of pathnames to monitor. :param recursive: ``True`` if recursive; ``False`` otherwise. r|rON)setschedulestarttimesleepr stopjoin)observer event_handlerrir|rjs r! observe_withrsq$ NH-YGH NN JJqM   MMOsA A)(A)c|D]R}|jD]=\}}t|}|di|}t|ddxs|} |j|| |?Ty)ajSchedules tricks with the specified observer and for the given watch path. :param observer: The observer thread into which to schedule the trick and watch. :param tricks: A list of tricks. :param pathname: A path name which should be watched. :param recursive: ``True`` if recursive; ``False`` otherwise. source_directoryNr~r\)itemsr getattrr) rrrjr|trickrWvalue trick_clshandlertrick_pathnames r!schedule_tricksrspL ;;= LKD%"4(I(%(G$W.@$GS8N   g~  K  LLr"files*zperform tricks from given file)nargshelpz --python-path.zPaths separated by z to add to the Python path.)defaultrz --intervalz --timeouttimeoutg?z?Use this as the polling interval/blocking timeout (in seconds).)r=rr&rz --recursive store_trueTz-Recursively monitor paths (defaults to True).)r;rrz--debug-force-pollingz[debug] Forces polling.)r;rz--debug-force-kqueuez[debug] Forces BSD kqueue(2).z--debug-force-winapizebug] Forces Windows API.z--debug-force-fseventsz[debug] Forces macOS FSEvents.z--debug-force-inotifyz [debug] Forces Linux inotify(7).)rCc|jr ddlm}|}n||jr ddlm}|}ngt s |jst rtjr ddl m }|}n2|jr ddl m}|}n|jr ddlm}|}nddlm}|}t)t+|j,g}|j.D],} ||j0} t2j4j7| st:j<| tA| } | tB} tF| vrt)| tFt2j4jI| xs1t2j4jKt3jL}tO| | ||jP | jS|jU| / tWjXd#tD$r} d tBd | d }tE|| d } ~ wwxYw#tZ$r*|D]"}|j]|j_$YnwxYw|D]}|jay )z;Command to execute tricks from a tricks configuration file.rPollingObserverKqueueObserverWindowsApiObserverInotifyObserverFSEventsObserverObserverrzNo z key specified in rNr~rO)1debug_force_pollingwatchdog.observers.pollingrdebug_force_kqueuewatchdog.observers.kqueuerrdebug_force_winapir is_windows)watchdog.observers.read_directory_changesrdebug_force_inotifywatchdog.observers.inotifyrdebug_force_fseventswatchdog.observers.fseventsrwatchdog.observersrrkrc python_pathrrosrgexistsOSErrorerrnoENOENTstrerrorrtCONFIG_KEY_TRICKSKeyErrorCONFIG_KEY_PYTHON_PATHdirnamerelpathgetcwdrr|rappendrrr unschedule_allrr)rr observer_clsrrrrr observers tricks_filerconfigreerrordir_pathos r! tricks_fromrsb >& <%  7 7]xObObOdP) ! !>& " "@'  0 Jt//01Izz#  5ww~~k*%,, ELL(A;O O[) )-.F "V + F#9: ;77??;/O277??299;3O&(dnnM")#, JJqM )+..@qQE5/q ( ) ! A    FFH  s*< H/H0 H-H((H-00I#"I# trick_pathsz5Dotted paths for all the tricks you want to generate.z--append-to-filez Appends the generated tricks YAML to a file. If not specified, prints to standard output.z-az --append-only append_onlyz If --append-to-file is not specified, produces output for appending instead of a complete tricks YAML file.)r=r;rzgenerate-tricks-yamlcddl}t|j}t|t }|j D],}t |}|j|j.|j}|j|jt|i}|tdz }|j1|js||z}t j"j|yt$j&j)|js||z}t+|jdd5}|j|dddy#1swYyxYw)zLCommand to generate Yaml configuration for tricks named on the command line.rNz: azutf-8)encoding)rnrcrrkrrr write generate_yamlgetvalueclosedumprrappend_to_filerrfstdoutrrgrro) rrn python_pathsoutput trick_pathrcontentheaderfiles r!tricks_generate_yamlrHsBd../LL! ZF&&0 z*  Y,,./0ooG LLN YY. = >F "#3''F "w&G !ww~~d112w&G $%%sW =  JJw    s 0E  E directoriesz%Directories to watch. (default: '.').)rrrz-pz --patternz --patternsryz9Matches event paths with these patterns (separated by ;).)r=rrz-iz--ignore-patternz--ignore-patternsrzrHz9Ignores event paths with these patterns (separated by ;).z-Dz--ignore-directoriesignore_directorieszIgnores events for directories.z-Rz%Monitors the directories recursively.z2Use this as the polling interval/blocking timeout.cddlm}t|j|j\}}||||j }|j r ddlm}|}n||jr ddl m }|}ngts |jstrtjr ddlm}|}n2|j$r ddlm} | }n|j*r ddlm} | }ndd lm} | }||j4 } t7| ||j8|j: y ) z1Command to log file system events to the console.r) LoggerTrick)ryrzrrrrrrrrr~N)watchdog.tricksrr{ryrzrrrrrrrrrr rrrrrrrrrrrrrrr|) rrryrzrrrrrrrrrs r!logrsN, .t}}d>R>R SHo'22G >& <%  7 7]xObObOdP) ! !>& " "@'  0 DLL1H7D$4$4Or"zDirectories to watch.z-cz --commandr]am Shell command executed in response to matching events. These interpolation variables are available to your command string: ${watch_src_path} - event source path ${watch_dest_path} - event destination path (for moved events) ${watch_event_type} - event type ${watch_object} - 'file' or 'directory' Note: Please ensure you do not use double quotes (") to quote your command string. That will force your shell to interpolate before the command is processed by this command. Example: --command='echo "${watch_src_path}"' F)r=rr;rz-wz--waitwait_for_processzDWait for process to finish to avoid multiple simultaneous instances.z-Wz--dropdrop_during_processzhIgnore events that occur while command is still being executed to avoid multiple simultaneous instances.cddlm}|jsd|_|jr ddlm}|}nddlm}|}t|j|j\}}||j|||j|j|j}||j}t|||j |j"y) zDCommand to execute shell commands in response to file system events.r)ShellCommandTrickNrr)ryrzrrrrr~)rrr]rrrrrr{ryrzrrrrrrr|) rrrrrryrzrrs r! shell_commandrsn2 <<  >& / .t}}d>R>R SHo '22.. 44 GDLL1H7D$4$4Or"z,Long-running command to run in a subprocess.)r command_argsargz Command arguments. Note: Use -- before the command arguments, otherwise watchmedo will try to interpret them. )metavarrrz-dz --directory DIRECTORYrzLDirectory to watch. Use another -d or --directory option for each directory.)r=rr;rz--signalsignalSIGINTz6Stop the subprocess with this signal (default SIGINT).z --kill-after kill_afterg$@zYWhen stopping, kill the subprocess after the specified timeout in seconds (default 10.0).z--debounce-intervaldebounce_intervalgzwAfter a file change, Wait until the specified interval (in seconds) passes with no file changes, and only then restart.z--no-restart-on-command-exitrestart_on_command_exit store_falsez.Don't auto-restart the command after it exits.c  |jr ddlm}|}nddlm}|}ddl ddlm}|jsdg|_|j jdrt |j nt|j } j jht drj j d fd }D]} j ||t#|j$|j&\}} |j(g} | j+|j,|| || |j.||j0|j2|j4 } | j7||j8 } t;| | |j|j< | jAy#t>$rYwxYw#| jAwxYw)zLCommand to start a long-running subprocess and restart it on matched events.rrrN)AutoRestartTrickrSIGSIGHUPcVD]}j|j t)N)rSIG_IGNr )_signum_framesignumrtermination_signalss r!handler_termination_signalz0auto_restart..handler_termination_signals*) 2F MM&&.. 1 2##r")ryrzr stop_signalrdebounce_interval_secondsrrr~)rzsignal._SIGNUMrobjectr0r1)!rrrrrrrrr startswithrr/SIGTERMrhasattraddrr{ryrzr]extendrrrrrrrrr|r r)rrrrrrrrryrzr]rrrrs @@r! auto_restartrgs~ >& / 0   537++2H2H2O'&$++.UXY]YdYdUeK">>6==9vx  .$ &: f89:!/t}}d>R>R SHo||nG NN4$$%'22??"&"8"8 $ < < G MMODLL1HXw(8(8DNNS   !     s$ #F>> G G G  G Gc eZdZy) LogLevelErrorN)r'r4r5r\r"r!r r sr"r ct|jxsg}|dkr d}t||dkDr d}t|gdd|zS)NrMz&-q/--quiet may be specified only once.z,-v/--verbose may be specified up to 2 times.)ERRORWARNINGINFODEBUGrO)sumrKr )rrKrs r!_get_log_level_from_argsrsRDNN(b)I2~8E""1}>E"" 0Y ??r"ctj}|jtjy t |}tjdj| |j|y#t $rV}t d|jdtjt|jjYd}~yd}~wwxYw#t$rYywxYw)zEntry-point function.NrOzError: r)rwatchdog)cli parse_argsr< print_helprr printrrfstderrrSlogging getLoggersetLevelrPKeyboardInterrupt)r log_levelexcs r!mainr!s >> D  ,T2  j!**95 $    }%CJJ7(()446 s* A9'C9 CA CC C'&C'__main__)r@r2rr r0Argument)rzlist[Argument]rBz!_SubParsersAction[ArgumentParser]rCzlist[str] | Noner0r)rbr2r^r2r0r3)rir3rdr/r0r1)rrr2r0dict)rwr2rxr2r^r2r0ztuple[list[str], list[str]]) rrrrrir3r|boolr0r1) rrrz list[dict]rjr2r|r%r0r1)rrr0r1)rrr0r2)r0r/)Fr6 __future__rrrros.pathrfrargparserriortextwraprtypingrr watchdog.utilsr r r watchdog.versionr rrrwatchdog.eventsrrrwatchdog.observers.apir basicConfigrrrrr8rrUadd_subparsers subparsersrStupler?r2r#rAr]pathseprcrkrtr{rrfloatrrrrr Exceptionr rr!r'exitr\r"r!r8s #   @%FF+56/3',,'&!/!. 4FMBYG   ]  3  cC '1;$(   ."   >8:zz*;< ) (HK % %.1 %AD %  %)    :L* *JK &rzzn4OP   R    @  (D]^ "0  ".  $1  #3 K*V Y-\>]-\>B  H  &rzzn4OP  C    H  %8((;> ?> :  8     L      "L     "%2     8     E   (D]^ "0  ".  $1  #3 {BDJ(PKDJ(PV c3=TU    2    L      "L     "%2     8     E     #W     &B   (D]^cRTjPkTjP< !OP     _      L      "L     "%2     8     E    I  (D]^ l    !$K    ** A  eY[x:y[x:z I @ . z CHHTVr"