
    zce[                        d 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ZddlmZmZ ddlmZ  ej        ej                   d	Zd
Z G d de	          ZdZ eee          Ze                    dde           e                    d          Zd Zg eg fdZej         fdZ!ddZ"d Z#ddZ$d Z%d Z& e eddd            ed!d"d#ej         d$%           ed&d'd(d)e'd*+           ed,d-d.%           ed/d0d1%           ed2d0d3%           ed4d0d5%           ed6d0d7%           ed8d0d9%          g	d	g:          d;             Z( e ed<dd=            ed!d"d#ej         d$%           ed>dd?%           ed@dAdBd0dCD          gdEg:          dF             Z) e edGdd"dHI           edJdKdLdMddND           edOdPdQdRdSdTD           edUdVdWd0dXdYZ           ed[d,d\d0dXd]Z           ed&d'd(d)e'd^+           ed_d0d`%           ed/d0d1%           ed2d0d3%           ed4d0d5%           ed6d0d7%           ed8d0d9%          g          da             Z* e edGdd"dbI           edcdddddeD           edJdKdLdMddND           edOdPdQdRdSdTD           edUdVdWd0dXdYZ           ed[d,d\d0dXd]Z           ed&d'd(d)e'd^+           edfdgdhdXd0dij           edkdldmdXd0dnj           ed/d0d1%          g
          do             Z+ e eddpq           edrdsddtu           edvdwdGdxdydz{           edJdKdLdMddND           edOdPdQdRdSdTD           edUdVdWd0dXdYZ           ed[d,d\d0dXd]Z           ed&d'd(d)e'd^+           ed|d}d~dD           ed/d0d1%           eddddD          g          d             Z,d Z-e.dk    r e-             dS dS )u   
:module: watchdog.watchmedo
:author: yesudeep@google.com (Yesudeep Mangalapilly)
:author: contact@tiger-222.fr (Mickaël Schoentgen)
:synopsis: ``watchmedo`` shell script utility.
    N)ArgumentParserRawDescriptionHelpFormatter)StringIO)dedent)WatchdogShutdown
load_class)VERSION_STRING)leveltrickszpython-pathc                   .     e Zd ZdZdd fd
Z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    ||d<    t                      j        |i | d S )Nr   )super__init__)selfr   argskwargs	__class__s       2lib/python3.11/site-packages/watchdog/watchmedo.pyr   zHelpFormatter.__init__6   s0    &7"#$)&)))))    c                 r    t          |                                          dz   }|                                S )Nz

)r   strip
splitlines)r   textwidths      r   _split_lineszHelpFormatter._split_lines;   s.    d||!!##f,   r   )__name__
__module____qualname____doc__r   r   __classcell__)r   s   @r   r   r   ,   s`          12 * * * * * * *
! ! ! ! ! ! !r   r   zCopyright 2011 Yesudeep Mangalapilly <yesudeep@gmail.com>.
Copyright 2012 Google, Inc & contributors.

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&   command)destc                  $    t          |           |fS )z^Convenience function to properly format arguments to pass to the
      command decorator.
    )list)name_or_flagsr   s     r   argumentr-   K   s     &&r   c                       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                             dd          }t          | j                  }                    ||t
                    }D ]1} |j        |d         i |d          |                    |            2d S )N_-)descriptionaliasesr%   r      )func)r   replacer   r"   
add_parserr   add_argumentset_defaults)r5   namedescparserargr   cmd_aliasesparents        r   	decoratorzcommand.<locals>.decorator[   s    }$$S#..dl##""4/3+63@ # B B  	+ 	+CFQ23q6222T****	+ 	+r    )r   r?   r>   r@   s   ``` r   r(   r(   R   s0    	+ 	+ 	+ 	+ 	+ 	+ 	+ r   c                 F    t          |                     |                    S )z
    Splits 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.
    )r+   split)pathname_spec	separators     r   
path_splitrF   h   s      ##I..///r   c                 b    | ddd         D ]"}t           j                            ||           #dS )z
    Adds 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.
    N)syspathinsert)	pathnamesindexpathnames      r   add_to_sys_pathrO   t   s@     dddO ) )x(((() )r   c                     t          | d          5 }t          j        |                                          cddd           S # 1 swxY w Y   dS )z
    Loads the YAML configuration from the specified file.

    :param tricks_file_path:
        The path to the tricks configuration file.
    :returns:
        A dictionary of configuration information.
    rbN)openyaml	safe_loadread)tricks_file_pathnamefs     r   load_configrX      s     
"D	)	) (Q~affhh''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   &AAA;c                 p    |                      |          }|                     |          }|dgk    rg }||fS )zc
    Parses pattern argument specs and returns a two-tuple of
    (patterns, ignore_patterns).
     )rC   )patterns_specignore_patterns_specrE   patternsignore_patternss        r   parse_patternsr`      sI    
 ""9--H*00;;O2$ o&&r   c                    t          |          D ]}|                     |||           |                                  	 	 t          j        d           # t
          $ r |                                  Y nw xY w|                                  dS )al  
    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.
    Tr4   N)setschedulestarttimesleepr   stopjoin)observerevent_handlerrL   	recursiverN   s        r   observe_withrl      s     	NN > >-9====NN	JqMMM	   MMOOOOOs   A A65A6c                     |D ]j}t          |                                          D ]F\  }}t          |          } |di |}t          |dd          p|}	|                     ||	|           GkdS )ao  
    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_directoryNrA   )r+   itemsr   getattrrc   )
ri   r   rN   rk   trickr:   value
TrickClasshandlertrick_pathnames
             r   schedule_tricksrv      s      B B.. 	B 	BKD%#D))J j))5))G$W.@$GGS8Ng~yAAAA		BB Br   files*zperform tricks from given file)nargshelpz--python-path.zPaths separated by z to add to the Python path.)defaultrz   z
--intervalz	--timeouttimeoutg      ?z?Use this as the polling interval/blocking timeout (in seconds).)r)   r|   typerz   z--recursiveTzRecursively monitor paths.z--debug-force-pollingFz[debug] Forces polling.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).)r>   c           	         | j         rddlm} n>| j        rddlm} n0| j        rddlm} n"| j	        rddl
m} n| j        rddlm} nddlm} t#          t%          | j                             g }| j        D ]e} || j                  }t,          j                            |          s7t3          t4          j        t-          j        t4          j                  |          t;          |          }	 |t<                   }n)# t>          $ r t?          d	t<          d
|d          w xY wt@          |v rt#          |t@                              t,          j        !                    |          }|s0t,          j        "                    t-          j#                              }tI          |||| j%                   |&                                 |'                    |           g	 	 tQ          j)        d           # tT          $ r0 |D ]*}|+                                 |,                                 +Y nw xY w|D ]}|-                                 dS )zE
    Command to execute tricks from a tricks configuration file.
    r   PollingObserverKqueueObserverWindowsApiObserverInotifyObserverFSEventsObserverObserverr}   zNo z key specified in r{   Tr4   N).debug_force_pollingwatchdog.observers.pollingr   debug_force_kqueuewatchdog.observers.kqueuer   debug_force_winapi)watchdog.observers.read_directory_changesr   debug_force_inotifywatchdog.observers.inotifyr   debug_force_fseventswatchdog.observers.fseventsr   watchdog.observersr   rO   rF   python_pathrw   r}   osrJ   existsOSErrorerrnoENOENTstrerrorrX   CONFIG_KEY_TRICKSKeyErrorCONFIG_KEY_PYTHON_PATHdirnamerelpathgetcwdrv   rk   rd   appendre   rf   r   unschedule_allrg   rh   )	r   r   	observerstricks_fileri   configr   dir_pathos	            r   tricks_fromr      s   F  0JJJJJJJ		  0HHHHHHH		  
0	+ 	+ 	+ 	+ 	+ 	+ 	+		! 0JJJJJJJ		" 0LLLLLLL 	0/////Jt/00111Iz # #8DL111w~~k** 	P%,EL(A(A;OOO[))	<-.FF 	< 	< 	<(,,,kkk; < < <	< "V+ 	<F#9:;;;7??;// 	4wry{{33H&(DNCCC""""	JqMMM	    	 	AFFHHHH	 	   	 s   1C??&D%G5 57H/.H/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|   rz   zgenerate-tricks-yamlc                    t          | j                  }t          |           t                      }| j        D ]8}t          |          }|                    |                                           9|                                }|	                                 t          j        t          |i          }|dt          z  z  }| j        -| j        s||z   }t           j                            |           dS t$          j                            | j                  s||z   }t+          | j        d          5 }|                    |           ddd           dS # 1 swxY w Y   dS )zV
    Command to generate Yaml configuration for tricks named on the command line.
    z%s:
Nab)rF   r   rO   r   r   r   writegenerate_yamlgetvaluecloserS   dumpr   r   append_to_filer   rI   stdoutr   rJ   r   rR   )r   python_pathsoutput
trick_pathrs   contentheaders          r   tricks_generate_yamlr   !  s   . d.//LL!!!ZZF& 1 1

++
Z--//0000ooG
LLNNNY.=>>F
g)))F 	" 	'w&G
!!!!!w~~d122 	'w&G$%t,, 	"LL!!!	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	"s   4EEEdirectoriesz%Directories to watch. (default: '.').)ry   r|   rz   z-pz	--patternz
--patternsr^   z9Matches event paths with these patterns (separated by ;).z-iz--ignore-patternz--ignore-patternsr_   r[   z9Ignores event paths with these patterns (separated by ;).z-Dz--ignore-directoriesignore_directories
store_truezIgnores events for directories.)r)   r|   r'   rz   z-Rrk   z%Monitors the directories recursively.z2Use this as the polling interval/blocking timeout.z--tracez!Dumps complete dispatching trace.c                    ddl m} ddlm} | j        r|                    |           t          | j        | j                  \  }} |||| j	                  }| j
        rddlm} n>| j        rddlm} n0| j        rddlm} n"| j        rddlm} n| j        rdd	lm} ndd
lm}  || j                  }t9          ||| j        | j                   dS )z;
    Command to log file system events to the console.
    r   )echo)LoggerTrick)r^   r_   r   r   r   r   r   r   r   r   N)watchdog.utilsr   watchdog.tricksr   trace
echo_classr`   r^   r_   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   rl   r   rk   )r   r   r   r^   r_   rt   r   ri   s           r   logr   Q  s}   p $#####++++++z %$$$ 	t}d&:;; Hok8*9-1-DF F FG  0JJJJJJJ		  0HHHHHHH		  
0	+ 	+ 	+ 	+ 	+ 	+ 	+		! 0JJJJJJJ		" 0LLLLLLL 	0/////x---H7D$4dnEEEEEr   zDirectories to watch.z-cz	--commandam  
    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}"'
    z-wz--waitwait_for_processzDWait for process to finish to avoid multiple simultaneous instances.)r)   r'   r|   rz   z-Wz--dropdrop_during_processzhIgnore events that occur while command is still being executed to avoid multiple simultaneous instances.c                 4   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                   dS )zN
    Command to execute shell commands in response to file system events.
    r   )ShellCommandTrickNr   r   )shell_commandr^   r_   r   r   r   r   )r   r   r(   r   r   r   r   r   r`   r^   r_   r   r   r   r}   rl   r   rk   )r   r   r   r^   r_   rt   ri   s          r   r   r     s    V 211111<  0JJJJJJJ////// .t}/3/C!E !EHodl)10?373J151F484LN N NG x---H7D$4dnEEEEEr   z,Long-running command to run in a subprocess.)rz   command_argsr=   z
    Command arguments.

    Note: Use -- before the command arguments, otherwise watchmedo will
    try to interpret them.
    )metavarry   rz   z-dz--directory	directoryr   zLDirectory to watch. Use another -d or --directory option for each directory.)r)   r   r'   rz   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).c                    | j         rddlm} nddlm} ddlm} ddl| j        sdg| _        | j        	                    d          rt          | j                  }nt          | j                  }j        j        hfd}D ]}                    ||           t          | j        | j                  \  }}| j        g}|                    | j                    ||||| j        || j        	          }	|	                                  || j        
          }
	 t1          |
|	| j        | j                   n# t4          $ r Y nw xY w|	                                 dS # |	                                 w xY w)zV
    Command to start a long-running subprocess and restart it on matched events.
    r   r   r   )AutoRestartTrickNr{   SIGc                 R    D ]}                     |j                   t          )N)r   SIG_IGNr   )_signum_framesignumr   termination_signalss      r   handler_termination_signalz0auto_restart.<locals>.handler_termination_signal^  s1    ) 	2 	2FMM&&.1111r   )r(   r^   r_   r   stop_signalr   r   )r   r   r   r   r   r   r   r   r   
startswithrp   intSIGTERMr   r`   r^   r_   r(   extendr   r   r   rd   r}   rl   rk   r   rg   )r   r   r   r   r   r   r^   r_   r(   rt   ri   r   r   s              @@r   auto_restartr     s   B  0JJJJJJJ//////000000MMM !5 {e$$ 'fdk22$+&& ">6=9      & : :f89999 .t}/3/C!E !EHo|nGNN4$%%%w(0/>262I+6*./; ; ;G MMOOOx---HXw(8$.IIII    	s*   #E  ?E&  
E
E& EE& &E<c                      t                                           } | j        t                                            dS |                     |            dS )zEntry-point function.N)cli
parse_argsr(   
print_helpr5   )r   s    r   mainr   {  sD    >>D| 		$r   __main__)r   )rY   )/r"   r   loggingr   os.pathrI   re   argparser   r   ior   textwrapr   rS   r   r   r   watchdog.versionr	   basicConfigINFOr   r   r   r$   r   r8   add_subparsers
subparsersr-   r(   pathseprF   rO   rX   r`   rl   rv   floatr   r   r   r   r   r   r   rA   r   r   <module>r      s	  "    				  



  @ @ @ @ @ @ @ @              7 7 7 7 7 7 7 7 + + + + + +  ', ' ' ' ' & ! ! ! ! !/ ! ! !(
4 nFMBBB   Y  G G GY//
' ' ' JB    , )+
 	0 	0 	0 	0) ) ) )
( 
( 
(	' 	' 	' 	'  0B B B, 	((78: : : (?WbjWWWY Y Y (<!Y[ [ [ (=46 6 6 (* 13 3 3 () 79 9 9 () 57 7 7 (+ 8: : : (* :< < <7
=< Z=! ! !>6 6?! !>6r 	((=OQ Q Q (?WbjWWWY Y Y (%CD D D
 (4"% H	I I I
J$ --%/ / /&" "'/ /&": 	((=AC C C (4"SU U U (4%&)SU U U (4), &9; ; ; (4 # &?A A A (<!LN N N (9 ;= = = (* 13 3 3 () 79 9 9 () 57 7 7 (+ 8: : : (* :< < <c3
= 3> 3>hF Fi3> 3>hFD 	((=/1 1 1 (4!		 	 	. (4"SU U U (4%&)SU U U (4), &9; ; ; (4 # &?A A A (<!LN N N (4*& ^	` ` `
 (4-& I	J J J (* 13 3 3IF
4 F5 F5NF FOF5 F5NF4 	((9FH H H
(> 	 	 	 (4 %&")* * * (4"SU U U (4%&)SU U U (4), &9; ; ; (4 # &?A A A (<!LN N N (: #PR R R (* 13 3 3 (>$01 1 1o;
2 ;3 ;3x4 4y;3 ;3x4n   z DFFFFF r   