
    tnilc                       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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+i Z,e-e.e/         ef         Z0dd!Z1e+dd"dd*Z2ej3        d+dd/Z4dd0dd5Z5dd8Z6d9d+dd=Z7ddDZ8ddGZ9 e2 e1dHdIdJK           e1dLdMdNej3        dOP           e1dQdRdSdTe:dUV           e1dWdXdYdZ[           e1d\dXd]^           e1d_dXd`^           e1dadXdb^           e1dcdXdd^           e1dedXdf^          g	dgg          ddi            Z; e2 e1djdIdkK           e1dLdMdNej3        dOP           e1dlddmP           e1dndodpdXdqr          gdsgg          ddt            Z< e2 e1dudIdMdvw           e1dxdydzd{dId|}           e1d~ddddd}           e1ddddXdr           e1ddWdBdXdr           e1dQdRdSdTe:dV           e1d\dXd]^           e1d_dXd`^           e1dadXdb^           e1dcdXdd^           e1dedXdf^          g          dd            Z= e2 e1dudIdMdw           e1ddddd}           e1dxdydzd{dId|}           e1d~ddddd}           e1dddddXd           e1ddWdBdXdr           e1dQdRdSdTe:dV           e1ddddXdr           e1ddddXdr           e1d\dXd]^          g
          dd            Z> e2 e1dd           e1dddId           e1ddduddd           e1dxdydzd{dId|}           e1d~ddddd}           e1dddddXd           e1ddWdBdXdr           e1dQdRdSdTe:dV           e1dddd}           e1d\dXd]^           e1ddde:dV           e1ddde:dV           e1dddYdd          g          dd            Z? G d de@          ZAddZBddZCeDdk    r ejE         eC                       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.
    )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_positionargsr	   r   intkwargsreturnNonec               D    ||d<    t                      j        |i | d S )Nr   )super__init__)selfr   r   r   	__class__s       O/var/www/html/gpu-tools/venv/lib/python3.11/site-packages/watchdog/watchmedo.pyr!   zHelpFormatter.__init__0   s0    &7"#$)&)))))    strc                2    dt          |           j         dS )N<>)type__name__)r"   s    r$   __repr__zHelpFormatter.__repr__5   s    )4::&))))r%   textwidth	list[str]c                r    t          |                                          dz   }|                                S )Nz

)r   strip
splitlines)r"   r-   r.   s      r$   _split_lineszHelpFormatter._split_lines8   s.    d||!!##f,   r%   )r   r	   r   r   r   r	   r   r   )r   r&   )r-   r&   r.   r   r   r/   )r+   
__module____qualname____doc__r!   r,   r3   __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)destname_or_flagsr&   r   r	   r   Argumentc                 $    t          |           |fS )z\Convenience function to properly format arguments to pass to the
    command decorator.
    )list)r>   r   s     r$   argumentrB   N   s     &&r%   )parentcmd_aliasesr   list[Argument]rC   !_SubParsersAction[ArgumentParser]rD   list[str] | Noner   c                    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)

    funcr   r   c                   | j                             dd          }t          | j        pd          }	                    |pg |t
                    }|t          |<   |                                }|                    ddddd	
           |                    ddddd
           D ](\  }} |j        |i | |	                    |            )| S )N_- )aliasesdescriptionr9   z-qz--quiet	verbosityappend_const)r=   r;   constz-vz	--verbose   )rI   )
r+   replacer   r6   
add_parserr   command_parsersadd_mutually_exclusive_groupadd_argumentset_defaults)
rI   namedescparserverbosity_groupr>   r   r   rD   rC   s
          r$   	decoratorzcommand.<locals>.decoratord   s    }$$S#..dl(b))""41BPTfs"tt & ==??$$T9;~eg$hhh$$T;[Q_gh$iii%) 	+ 	+!M6F9&999T****r%   )rI   r   r   r    )r   rC   rD   r_   s   ``` r$   commandra   U   s5            r%   )	separatorpathname_specrb   r/   c               ,    |                      |          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)rc   rb   s     r$   
path_splitrg   t   s     y)))r%   )index	pathnamesrh   r   r   c               b    | ddd         D ]"}t           j                            ||           #dS )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.
    NrR   )syspathinsert)ri   rh   pathnames      r$   add_to_sys_pathro      s@     dddO ) )x(((() )r%   tricks_file_pathnamedictc                    ddl }t          | d          5 }|                    |                                          cddd           S # 1 swxY w Y   dS )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)rp   rt   fs      r$   load_configry      s     KKK	"D	)	) (Q~~affhh''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   'A		AA;patterns_specignore_patterns_spectuple[list[str], list[str]]c               p    |                      |          }|                     |          }|dgk    rg }||fS )z^Parses pattern argument specs and returns a two-tuple of
    (patterns, ignore_patterns).
    rM   re   )r{   r|   rb   patternsignore_patternss        r$   parse_patternsr      sG     ""9--H*00;;O2$_$$r%   observerr   event_handlerr   	recursiveboolc                   t          |          D ]}|                     |||           |                                  	 	 t          j        d           # t
          $ r |                                  Y nw xY w|                                  dS )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   TrT   N)setschedulestarttimesleepr
   stopjoin)r   r   ri   r   rn   s        r$   observe_withr      s    $ 	NN H H-YGGGGNN	JqMMM	    MMOOOOOs    A A76A7
list[dict]rn   c                   |D ]^}|                                 D ]G\  }}t          |          } |di |}t          |dd          p|}	|                     ||	|           H_dS )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   rn   r   trickr[   value	trick_clshandlertrick_pathnames
             r$   schedule_tricksr      s      L L ;;== 	L 	LKD%"4((Ii((%((G$W.@$GGS8Ng~KKKK		LL L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).)rD   r   c                    | j         r	ddlm} |}ni| j        r	ddlm} |}nYt          s| j        st          rt          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 ]k}	 || j                  }
t2          j                            |	          s7t9          t:          j        t3          j        t:          j                  |	          tA          |	          }	 |tB                   }n0# tD          $ r#}d	tB          d
|	d}tE          |          |d}~ww xY wtF          |v rt)          |tF                              t2          j        $                    |	          p/t2          j        %                    t3          j&                              }tO          |
||| j(                   |
)                                 |*                    |
           m	 	 tW          j,        d           # tZ          $ r0 |D ]*}|.                                 |/                                 +Y nw xY w|D ]}|0                                 dS )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   TrT   )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   ro   rg   python_pathr   r   osrl   existsOSErrorerrnoENOENTstrerrorry   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  ]  xObOdOd  PPPPPP)		!  >>>>>>&		" 	 @@@@@@' 	0/////Jt/00111Iz # #<555w~~k** 	P%,EL(A(A;OOO[))	)-.FF 	) 	) 	)Q+QQQQQE5//q(	) "V++F#9:;;;7??;//O27??29;;3O3O&(dnMMMM""""	JqMMM	     	 	AFFHHHH	 	   	 s*   D,,
E6EEH( (7I"!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 ]8}t          |          }|                    |                                           9|	                                }|
                                 |                    t          |i          }|t           dz  }| j        -| j        s||z   }t           j                            |           dS t$          j                            | j                  s||z   }t+          | j        dd          5 }|                    |           ddd           dS # 1 swxY w Y   dS )zLCommand to generate Yaml configuration for tricks named on the command line.r   Nz:
azutf-8)encoding)rt   rg   r   ro   r   r   r   writegenerate_yamlgetvalueclosedumpr   r   append_to_filer   rk   stdoutr   rl   r   ru   )	r   rt   python_pathsoutput
trick_pathr   contentheaderfiles	            r$   tricks_generate_yamlr   H  s   B KKKd.//LL!!!ZZF& 0 0
z**	Y,,..////ooG
LLNNNYY.=>>F
"''''F" 	'w&G
!!!!!w~~d122 	'w&G$%sW=== 	 JJw	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	  	 s   ;EE"%E"directoriesz%Directories to watch. (default: '.').)r   r   r   z-pz	--patternz
--patternsr   z9Matches event paths with these patterns (separated by ;).)r=   r   r   z-iz--ignore-patternz--ignore-patternsr   rM   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} |}ni| j	        r	ddl
m} |}nYt          s| j        st          rt          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        
          }t7          ||| j        | j                   dS )z1Command to log file system events to the console.r   )LoggerTrick)r   r   r   r   r   r   r   r   r   r   r   N)watchdog.tricksr   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   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   s                r$   logr     su   N ,+++++ .t}d>R S SHok'2  G   >>>>>>&		   <<<<<<%   7  ]  xObOdOd  PPPPPP)		!  >>>>>>&		" 	 @@@@@@' 	0/////|DL111H7D$4OOOOOOr%   zDirectories to watch.z-cz	--commandra   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                   dS )	zDCommand to execute shell commands in response to file system events.r   )ShellCommandTrickNr   r   )r   r   r   r   r   r   r   )r   r   ra   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )	r   r   r   r   r   r   r   r   r   s	            r$   shell_commandr     s    n 211111<    >>>>>>&////// .t}d>R S SHo'2. 4  G |DL111H7D$4OOOOO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           
     t   | j         r	ddlm} |}nddlm} |}ddlddlm} | j        sdg| _        | j        	                    d          rt          | j                  nt          | j                  }j        j        ht          d          r                    j                   dfd}D ]}                    ||           t#          | j        | j                  \  }}	| j        g}
|
                    | j                    ||
||	| j        || j        | j        | j                  }|                                  || j                  }	 t;          ||| j        | j                   n# t>          $ r Y nw xY w|                                  dS # |                                  w xY w)zLCommand to start a long-running subprocess and restart it on matched events.r   r   r   N)AutoRestartTrickr   SIGSIGHUP_signumsignal._SIGNUM_frameobjectr   r   c                R    D ]}                     |j                   t          )N)r   SIG_IGNr
   )r  r  signumr   termination_signalss      r$   handler_termination_signalz0auto_restart.<locals>.handler_termination_signal  s1    ) 	2 	2FMM&&.1111##r%   )r   r   r   stop_signalr   debounce_interval_secondsr   r   r   )r  r  r  r  r   r   )!r   r   r   r   r   r   r   r   r   
startswithr   r   SIGTERMr   hasattraddr   r   r   r   ra   extendr   r   r   r   r   r   r   r   r   r
   r   )r   r   r   r   r   r
  r	  r  r   r   ra   r   r   r   r  s                @@r$   auto_restartr  g  s.   ~   >>>>>>&//////MMM000000 !5 37+2H2H2O2Oe'&$+...UXY]YdUeUeK ">6=9vx   /...$ $ $ $ $ $ $ & : :f89999 .t}d>R S SHo|nGNN4$%%%'2?"&"8 $ <	 	 	G MMOOO|DL111HXw(8DNSSSSS     	s*   E; :F! ;
FF! FF! !F7c                      e Zd ZdS )LogLevelErrorN)r+   r4   r5   r`   r%   r$   r  r     s        Dr%   r  c                    t          | j        pg           }|dk     rd}t          |          |dk    rd}t          |          g dd|z            S )NrR   z&-q/--quiet may be specified only once.   z,-v/--verbose may be specified up to 2 times.)ERRORWARNINGINFODEBUGrT   )sumrP   r  )r   rP   r   s      r$   _get_log_level_from_argsr    sc    DN(b))I2~~8E"""1}}>E"""000Y??r%   c                    t                                           } | j        t                                            dS 	 t	          |           }ne# t
          $ rX}t          d|j        d          t          j	                   t          | j                                                  Y d}~dS d}~ww xY wt          j        d                              |           	 |                     |            n# t          $ r Y dS w xY wdS )zEntry-point function.NrT   zError: r   )r   watchdog   )cli
parse_argsr<   
print_helpr  r  printr   rk   stderrrW   logging	getLoggersetLevelrI   KeyboardInterrupt)r   	log_levelexcs      r$   mainr*    s   >>Dq,T22		   %%%CJ7777()44666qqqqq j!!**9555		$   ss 1s*   A 
B/AB**B/C0 0
C>=C>__main__)r>   r&   r   r	   r   r?   )r   rE   rC   rF   rD   rG   r   r   )rc   r&   rb   r&   r   r/   )ri   r/   rh   r   r   r   )rp   r&   r   rq   )r{   r&   r|   r&   rb   r&   r   r}   )
r   r   r   r   ri   r/   r   r   r   r   )
r   r   r   r   rn   r&   r   r   r   r   )r   r   r   r   )r   r   r   r&   )r   r   )Fr6   
__future__r   r   r$  r   os.pathrk   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  rY   add_subparsers
subparsersrW   tuplerA   r&   r?   rB   ra   pathseprg   ro   ry   r   r   r   floatr   r   r   r   r  	Exceptionr  r  r*  r+   exitr`   r%   r$   <module>r>     s    # " " " " "   				  



  @ @ @ @ @ @ @ @             % % % % % % % % F F F F F F F F F F + + + + + + 455555555666666//////333333  ', ' ' ' ' & ! ! ! ! !/ ! ! !.
4 nFMBBB   Y  G G G]33
cC ' ' ' ' 1;$(	     > 8:z * * * * * * ;< 
) 
) 
) 
) 
) 
)( ( ( ( HK
% 
% 
% 
% 
% 
%   :L L L L* 	*JKKKPrzPPP	
 	
 	

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

 	".	
 	
 	

 	$1	
 	
 	

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

 	PrzPPP	
 	
 	

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

 	".	
 	
 	

 	$1	
 	
 	

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