
    glc                       d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	m
Z
mZ ddlmZ ddlmZ ddlmZmZ ddlmZmZmZ dd	lmZ er dd
l	mZmZ ddlmZ ddlmZ ddlmZ ddl m!Z!  ejD                  ejF                         dZ$dZ% G d de      Z&dZ' e
e'e&      Z(e(jS                  dde       e(jU                  d      Z+i Z,e-e.e/   ef   Z0ddZ1e+dd	 	 	 	 	 	 	 ddZ2ejf                  dddZ4dd dd!Z5dd"Z6d#d	 	 	 	 	 	 	 dd$Z7	 	 	 	 	 	 	 	 	 	 dd&Z8dd'Z9 e2 e1d(d)d*+       e1d,d-d.ejf                  d/0       e1d1d2d3d4e:d56       e1d7d8d9d:;       e1d<d8d=>       e1d?d8d@>       e1dAd8dB>       e1dCd8dD>       e1dEd8dF>      g	dgG      ddH       Z; e2 e1dId)dJ+       e1d,d-d.ejf                  d/0       e1dKddL0       e1dMdNdOd8dPQ      gdRgG      ddS       Z< e2 e1dTd)d-dUV       e1dWdXdYdZd)d[\       e1d]d^d_d`dadb\       e1dcddded8dfQ       e1dgd7d%d8dhQ       e1d1d2d3d4e:di6       e1d<d8d=>       e1d?d8d@>       e1dAd8dB>       e1dCd8dD>       e1dEd8dF>      g      ddj       Z= e2 e1dTd)d-dkV       e1dldmdnddo\       e1dWdXdYdZd)d[\       e1d]d^d_d`dadb\       e1dcdddedpd8dfq       e1dgd7d%d8dhQ       e1d1d2d3d4e:di6       e1drdsdtd8duQ       e1dvdwdxd8dyQ       e1d<d8d=>      g
      ddz       Z> e2 e1dnd{|       e1d}d~d)d       e1dddTddd       e1dWdXdYdZd)d[\       e1d]d^d_d`dadb\       e1dcdddedpd8dfq       e1dgd7d%d8dhQ       e1d1d2d3d4e:di6       e1dddd\       e1d<d8d=>       e1ddde:d6       e1ddde:d6       e1ddd9ddq      g      dd       Z? G d de@      ZAddZBddZCeDdk(  r ej                   eC              yy)u   :module: watchdog.watchmedo
:author: yesudeep@google.com (Yesudeep Mangalapilly)
:author: contact@tiger-222.fr (Mickaël Schoentgen)
:synopsis: ``watchmedo`` shell script utility.
    )annotationsN)ArgumentParserRawDescriptionHelpFormatter)StringIO)dedent)TYPE_CHECKINGAny)WatchdogShutdownError
load_classplatform)VERSION_STRING)	Namespace_SubParsersAction)Callable)FileSystemEventHandler)ObserverType)BaseObserver)leveltrickszpython-pathc                  :     e Zd ZdZddd fdZddZd	dZ xZS )
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__)selfr   argskwargs	__class__s       G/var/www/openai/venv/lib/python3.12/site-packages/watchdog/watchmedo.pyr   zHelpFormatter.__init__0   s     &7"#$)&)    c                4    dt        |       j                   dS )N<>)type__name__)r   s    r!   __repr__zHelpFormatter.__repr__5   s    4:&&'q))r"   c                Z    t        |      j                         dz   }|j                         S )Nz

)r   strip
splitlines)r   textwidths      r!   _split_lineszHelpFormatter._split_lines8   s&    d|!!#f,  r"   )r   r	   r   intr   r	   returnNone)r0   str)r,   r2   r-   r/   r0   	list[str])r'   
__module____qualname____doc__r   r(   r.   __classcell__)r    s   @r!   r   r   &   s     => *
*!r"   r   u,  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.)epilogformatter_classz	--versionversion)actionr:   top_command)destc                     t        |       |fS )z\Convenience function to properly format arguments to pass to the
    command decorator.
    )list)name_or_flagsr   s     r!   argumentrA   N   s     &&r"   )parentcmd_aliasesc                    d fd}|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                   | j                   j                  dd      }t        | j                  xs d      }	j	                  |xs g |t
              }|t        |<   |j                         }|j                  ddddd	
       |j                  ddddd
       D ])  \  }} |j                  |i | |j                  |        + | S )N_- )aliasesdescriptionr9   z-qz--quiet	verbosityappend_const)r=   r;   constz-vz	--verbose   )func)
r'   replacer   r6   
add_parserr   command_parsersadd_mutually_exclusive_groupadd_argumentset_defaults)
rP   namedescparserverbosity_groupr@   r   r   rC   rB   s
          r!   	decoratorzcommand.<locals>.decoratord   s    }}$$S#.dll(b)""41BPTfs"t & ==?$$T9;~eg$h$$T;[Q_gh$i%)!M6F9&9T* &* r"   )rP   r   r0   r    )r   rB   rC   r[   s   ``` r!   commandr]   U   s     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_splitrc   t   s     y))r"   )indexc               ^    | ddd   D ]"  }t         j                  j                  ||       $ 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   )syspathinsert)	pathnamesrd   pathnames      r!   add_to_sys_pathrk      s(     ddOx( $r"   c                    ddl }t        | d      5 }|j                  |j                               cddd       S # 1 sw Y   yxY w)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.
    r   Nrb)yamlopen	safe_loadread)tricks_file_pathnamern   fs      r!   load_configrt      s2     	"D	)Q~~affh' 
*	)	)s	   :A;c               ^    | j                  |      }|j                  |      }|dgk(  rg }||fS )z^Parses pattern argument specs and returns a two-tuple of
    (patterns, ignore_patterns).
    rH   r`   )patterns_specignore_patterns_specr^   patternsignore_patternss        r!   parse_patternsr{      s>     ""9-H*00;O2$_$$r"   	recursivec                   t        |      D ]  }| j                  |||        | j                          	 	 t        j                  d       # t
        $ r | j                          Y nw xY w| j                          y)ag  Single 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|   rO   N)setschedulestarttimesleepr
   stopjoin)observerevent_handlerri   r|   rj   s        r!   observe_withr      sj    $ 	N-YG #NNJJqM   MMOs   A A)(A)c                   |D ]R  }|j                         D ]=  \  }}t        |      } |di |}t        |dd      xs |}	| j                  ||	|       ? T y)aj  Schedules 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   )
r   r   rj   r|   trickrW   value	trick_clshandlertrick_pathnames
             r!   schedule_tricksr      sb      ;;=KD%"4(I(%(G$W.@$GS8Ng~K	 ) r"   files*zperform tricks from given file)nargshelpz--python-path.zPaths separated by z to add to the Python path.)defaultr   z
--intervalz	--timeouttimeoutg      ?z?Use this as the polling interval/blocking timeout (in seconds).)r=   r   r&   r   z--recursive
store_trueTz-Recursively monitor paths (defaults to True).)r;   r   r   z--debug-force-pollingz[debug] Forces polling.)r;   r   z--debug-force-kqueuez[debug] Forces BSD kqueue(2).z--debug-force-winapiz[debug] Forces Windows API.z--debug-force-fseventsz[debug] Forces macOS FSEvents.z--debug-force-inotifyz [debug] Forces Linux inotify(7).)rC   c                   | j                   r	ddlm} |}n|| j                  r	ddlm} |}ngt        s| j                  st        rt        j                         r	ddl
m} |}n2| j                  r	ddlm} |}n| j                  r	ddlm} |}nddlm} |}t)        t+        | j,                               g }| j.                  D ],  }	 || j0                        }
t2        j4                  j7                  |	      s<t9        t:        j<                  t3        j>                  t:        j<                        |	      tA        |	      }	 |tB           }tF        |v rt)        |tF                  t2        j4                  jI                  |	      xs1 t2        j4                  jK                  t3        jL                               }tO        |
||| jP                         |
jS                          |jU                  |
       / 	 	 tW        jX                  d       # tD        $ r}d	tB        d
|	d}tE        |      |d}~ww xY w# tZ        $ r* |D ]"  }|j]                          |j_                          $ Y nw xY w|D ]  }|ja                           y)z;Command to execute tricks from a tricks configuration file.r   PollingObserverKqueueObserverWindowsApiObserverInotifyObserverFSEventsObserverObserverr   zNo z key specified in r   Nr~   rO   )1debug_force_pollingwatchdog.observers.pollingr   debug_force_kqueuewatchdog.observers.kqueuer   r   debug_force_winapir   
is_windows)watchdog.observers.read_directory_changesr   debug_force_inotifywatchdog.observers.inotifyr   debug_force_fseventswatchdog.observers.fseventsr   watchdog.observersr   rk   rc   python_pathr   r   osrg   existsOSErrorerrnoENOENTstrerrorrt   CONFIG_KEY_TRICKSKeyErrorCONFIG_KEY_PYTHON_PATHdirnamerelpathgetcwdr   r|   r   appendr   r   r
   unschedule_allr   r   )r   r   observer_clsr   r   r   r   r   	observerstricks_filer   configr   eerrordir_pathos                    r!   tricks_fromr      s   b >&		 	 <% 7 7]xObObOdP)		!	!>&		"	"@' 	0Jt//01Izz5ww~~k*%,,ELL(A;OO[)	)-.F
 "V+F#9:;77??;/O277??299;3O&(dnnM") ",JJqM   	)+..@qQE5/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;   r   zgenerate-tricks-yamlc                   ddl }t        | j                        }t        |       t	               }| j
                  D ],  }t        |      }|j                  |j                                . |j                         }|j                          |j                  t        |i      }|t         dz  }| j                  1| j                  s||z   }t         j"                  j                  |       yt$        j&                  j)                  | j                        s||z   }t+        | j                  dd      5 }|j                  |       ddd       y# 1 sw Y   yxY w)zLCommand to generate Yaml configuration for tricks named on the command line.r   Nz:
azutf-8)encoding)rn   rc   r   rk   r   r   r   writegenerate_yamlgetvalueclosedumpr   r   append_to_filer   rf   stdoutr   rg   r   ro   )	r   rn   python_pathsoutput
trick_pathr   contentheaderfiles	            r!   tricks_generate_yamlr   H  s   B d../LL!ZF&&
z*	Y,,./ ' ooG
LLNYY.=>F
"#3''F"w&G

!ww~~d112w&G$%%sW=JJw >==s   0EEdirectoriesz%Directories to watch. (default: '.').)r   r   r   z-pz	--patternz
--patternsry   z9Matches event paths with these patterns (separated by ;).)r=   r   r   z-iz--ignore-patternz--ignore-patternsrz   rH   z9Ignores event paths with these patterns (separated by ;).z-Dz--ignore-directoriesignore_directorieszIgnores events for directories.z-Rz%Monitors the directories recursively.z2Use this as the polling interval/blocking timeout.c                   ddl m} t        | j                  | j                        \  }} |||| j
                        }| j                  r	ddlm} |}n|| j                  r	ddl
m} |}ngt        s| j                  st        rt        j                         r	ddlm} |}n2| j$                  r	ddlm}	 |	}n| j*                  r	ddlm}
 |
}ndd	lm} |} || j4                  
      }t7        ||| j8                  | j:                         y)z1Command to log file system events to the console.r   )LoggerTrick)ry   rz   r   r   r   r   r   r   r   r   r~   N)watchdog.tricksr   r{   ry   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r|   )r   r   ry   rz   r   r   r   r   r   r   r   r   r   s                r!   logr     s    N , .t}}d>R>R SHo'22G >&		 	 <% 7 7]xObObOdP)		!	!>&		"	"@' 	0DLL1H7D$4$4Or"   zDirectories 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=   r   r;   r   z-wz--waitwait_for_processzDWait for process to finish to avoid multiple simultaneous instances.z-Wz--dropdrop_during_processzhIgnore events that occur while command is still being executed to avoid multiple simultaneous instances.c                   ddl m} | j                  sd| _        | j                  r	ddlm} |}nddlm} |}t        | j                  | j                        \  }} || j                  ||| j                  | j                  | j                        } || j                        }t        ||| j                   | j"                         y)	zDCommand to execute shell commands in response to file system events.r   )ShellCommandTrickNr   r   )ry   rz   r   r   r   r   r~   )r   r   r]   r   r   r   r   r   r{   ry   rz   r   r   r   r   r   r   r|   )	r   r   r   r   r   ry   rz   r   r   s	            r!   shell_commandr     s    n 2<< >&/ .t}}d>R>R SHo'22.. 44G DLL1H7D$4$4Or"   z,Long-running command to run in a subprocess.)r   command_argsargz
    Command arguments.

    Note: Use -- before the command arguments, otherwise watchmedo will
    try to interpret them.
    )metavarr   r   z-dz--directory	DIRECTORYr   zLDirectory to watch. Use another -d or --directory option for each directory.)r=   r   r;   r   z--signalsignalSIGINTz6Stop 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-intervaldebounce_intervalg        zwAfter a file change, Wait until the specified interval (in seconds) passes with no file changes, and only then restart.z--no-restart-on-command-exitrestart_on_command_exitstore_falsez.Don't auto-restart the command after it exits.c           
        | j                   r	ddlm} |}nddlm} |}ddlddlm} | j                  sdg| _        | j
                  j                  d      rt        | j
                        nt        | j
                        }j                  j                  ht        d      rj                  j                          dfd	}D ]  }j                  ||        t#        | j$                  | j&                        \  }}	| j(                  g}
|
j+                  | j,                          ||
||	| j.                  || j0                  | j2                  | j4                  
      }|j7                           || j8                        }	 t;        ||| j                  | j<                         |jA                          y# t>        $ r Y w xY w# |jA                          w xY w)zLCommand to start a long-running subprocess and restart it on matched events.r   r   r   N)AutoRestartTrickr   SIGSIGHUPc                V    D ]  }j                  |j                           t        )N)r   SIG_IGNr
   )_signum_framesignumr   termination_signalss      r!   handler_termination_signalz0auto_restart.<locals>.handler_termination_signal  s%    )FMM&&..1 *##r"   )ry   rz   r   stop_signalr   debounce_interval_secondsr   r   r~   )r   zsignal._SIGNUMr   objectr0   r1   )!r   r   r   r   r   r   r   r   r   
startswithr   r/   SIGTERMr   hasattraddr   r{   ry   rz   r]   extendr   r   r   r   r   r   r   r   r|   r
   r   )r   r   r   r   r   r   r   r   ry   rz   r]   r   r   r   r   s                @@r!   auto_restartr  g  s   ~ >&/05 37++2H2H2O'&$++.UXY]YdYdUeK ">>6==9vx .$ &f89 & !/t}}d>R>R SHo||nGNN4$$%'22??"&"8"8 $ < <	G MMODLL1HXw(8(8DNNS 	 !  	s$   
#F> >	G
G 	G

G Gc                      e Zd Zy)LogLevelErrorN)r'   r4   r5   r\   r"   r!   r
  r
     s    r"   r
  c                    t        | j                  xs g       }|dk  rd}t        |      |dkD  rd}t        |      g dd|z      S )NrM   z&-q/--quiet may be specified only once.   z,-v/--verbose may be specified up to 2 times.)ERRORWARNINGINFODEBUGrO   )sumrK   r
  )r   rK   r   s      r!   _get_log_level_from_argsr    sR    DNN(b)I2~8E""1}>E""0Y??r"   c                    t         j                         } | j                  t         j                          y	 t	        |       }t        j                  d      j                  |       	 | j                  |        y# t
        $ rV}t        d|j                  d    t        j                         t        | j                     j                          Y d}~yd}~ww xY w# t        $ r Y yw xY w)zEntry-point function.NrO   zError: r   )r   watchdog   )cli
parse_argsr<   
print_helpr  r
  printr   rf   stderrrS   logging	getLoggersetLevelrP   KeyboardInterrupt)r   	log_levelexcs      r!   mainr!    s    >>D,T2	
 j!**95		$   }%CJJ7(()446  s*   A9 'C 9	CACC	C'&C'__main__)r@   r2   r   r	   r0   Argument)r   zlist[Argument]rB   z!_SubParsersAction[ArgumentParser]rC   zlist[str] | Noner0   r   )rb   r2   r^   r2   r0   r3   )ri   r3   rd   r/   r0   r1   )rr   r2   r0   dict)rw   r2   rx   r2   r^   r2   r0   ztuple[list[str], list[str]])
r   r   r   r   ri   r3   r|   boolr0   r1   )
r   r   r   z
list[dict]rj   r2   r|   r%  r0   r1   )r   r   r0   r1   )r   r   r0   r2   )r0   r/   )Fr6   
__future__r   r   r  r   os.pathrf   r   argparser   r   ior   textwrapr   typingr   r	   watchdog.utilsr
   r   r   watchdog.versionr   r   r   r   watchdog.eventsr   r   r   watchdog.observers.apir   basicConfigr  r   r   r   r8   r  rU   add_subparsers
subparsersrS   tupler?   r2   r#  rA   r]   pathseprc   rk   rt   r{   r   r   floatr   r   r   r   r  	Exceptionr
  r  r!  r'   exitr\   r"   r!   <module>r8     s   #   	  
  @   % F F +56/3   ',, ' & !/ !.
4 FMB   Y  G]3
cC ' 1;$(	
 . "	
 > 8:zz * ;< 
)( HK
%
%.1
%AD
% 
%) 
  
:L* 	*JK&rzzn4OP	

 	R	
 	@		
 	(D]^"0	

 	".	

 	$1	

 	#3	
K*V 
Y-\>]-\>B 	H	

 	&rzzn4OP	

 	C	
 	H	
%8 ((;> ?> : 	8		
 	L	
 	"L	
 	"%2	
 	8	
 	E	
 	(D]^"0	

 	".	

 	$1	

 	#3	
{BDJ(PKDJ(PV 	c3=TU	
2 	L	
 	"L	
 	"%2	
 	8	
 	E	
 	#W	
 	&B	
 	(D]^cRTjPkTjP< 	!OP	
	
 	_	
 	L	
 	"L	
 	"%2	
 	8	
 	E	
 	I		
 	(D]^l	
 	!$K	
 	** A	
eY[x:y[x:z	I 	@. zCHHTV r"   