
    y9>i              	          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mZmZ ddl	m
Z
mZmZ ddlmZ d0ded	ed
dfdZded
dfdZded
dfdZdee         d
dfdZdeded
dfdZded
efdZd1dedz  ded
efdZded
efdZd2dededed
efdZdeded
efdZdeded
efd Zd3d!ed"ed#ed
dfd$Zded
edz  fd%Zd&ed
efd'Zd&ed(ed)ed
dfd*Z d&ed(ed
dfd+Z!d(ed
dfd,Z"ded
dfd-Z#ded
dfd.Z$ded
dfd/Z%dS )4z%File and directory utility functions.    N)SequenceCallable   )log_infolog_warning	log_error)PatoolErrorTfilename	onlyfilesreturnc                 :   t           j                            |           st          d|  d          t          j        | t           j                  st          d|  d          |r2t           j                            |           st          d|  d          dS dS )z5Ensure that given filename is a valid, existing file.file `z' was not foundz' is not readable`z' is not a fileN)ospathexistsr	   accessR_OKisfile)r
   r   s     Q/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/patoolib/fileutil.pycheck_existing_filenamer      s    7>>(## ><8<<<===9Xrw'' @>8>>>??? 911 97h7778889 9 9 9    c                 j    t          j        | t           j                  st          d|  d          dS )z+Ensure that the given filename is writable.r   z' is not writableN)r   r   W_OKr	   r
   s    r   check_writable_filenamer   %   s?    9Xrw'' @>8>>>???@ @r   c                 j    t           j                            |           rt          d|  d          dS )z+Check that filename does not already exist.z cannot overwrite existing file `'N)r   r   r   r	   r   s    r   check_new_filenamer   +   s?    	w~~h JHXHHHIIIJ Jr   	filenamesc                 T    | st          d          | D ]}t          |d           dS )zCCheck that file list is not empty and contains only existing files.z)cannot create archive with empty filelistF)r   N)r	   r   )r    r
   s     r   check_archive_filelistr"   1   sI     GEFFF ; ;E:::::; ;r   flagsc                 0   	 t          j        |           j        }n-# t          $ r }t	          d|  d|            Y d}~dS d}~ww xY w||z  sH	 t          j        | ||z             dS # t          $ r }t	          d|  d|            Y d}~dS d}~ww xY wdS )z5Set mode flags for given filename if not already set.zcould not stat `z': Nzcould not set mode flags for `)r   lstatst_modeOSErrorr   chmod)r
   r#   modeerrs       r   set_moder+   9   s    x!!)   9x99C99::: 5L M	MHXut|,,,,, 	M 	M 	MKKKcKKLLLLLLLLL	MM Ms,    
AAAA) )
B3BBc                 @    t           j                            |           S )z*Return file size in Bytes, or -1 on error.)r   r   getsizer   s    r   get_filesizer.   H   s    7??8$$$r   Unpack_dirprefixc                 0    t          j        d||           S )z,Return a temporary directory for extraction. )suffixr1   r0   )tempfilemkdtemp)r0   r1   s     r   tmpdirr7   M   s    2f#>>>>r   c                     t           j                            t           j                            |                     \  }}|                    d          r(|dk    r"t           j                            |          \  }}|S )zReturn the basename without extension of given filename
    For compressed TAR archives, the filename without the .tar
    extension is returned, ie. output of 'a.tar.xz' will be
    'a'.
    z.tar)r   r   splitextbasenameendswith)r
   r:   _s      r   stripextr=   R   sk     '""27#3#3H#=#=>>KHa   1X%7%7g&&x00!Or   r3   	directoryarchive	extensionc                 \   t           j                            | t          |                    }t           j                            ||z             rYd}| | }t           j                            ||z             r-|dz  }| | }t           j                            ||z             -|}||z   S )zDGet output filename if archive is in a single file format like gzip.r   )r   r   joinr=   r   )r>   r?   r@   outfileinewfiles         r   get_single_outfilerF   ^   s    gll9hw&7&788G	w~~g	)** /a//gnnWy011 	&FA o!ooG gnnWy011 	& Yr   	filename1	filename2c                     | |k    rdS t           j        dk    r t           j                            | |          S t	          | |          S )a  Check if filename1 and filename2 point to the same file object.
    There can be false negatives, i.e. the result is False, but it is
    the same file anyway. Reason is that network filesystems can create
    different paths to the same physical file.
    Tposix)r   namer   samefileis_same_filenamerG   rH   s     r   is_same_filerO   l   sI     It	w'w	9555Iy111r   c                     t           j                            |           t           j                            |          k    S )z7Check if filename1 and filename2 are the same filename.)r   r   realpathrN   s     r   rM   rM   y   s-    7I&&"'*:*:9*E*EEEr   srcdst	verbosityc                    |dk    rt          d|  d|            	 t          j        | |           dS # t          t          f$ rB 	 t          j        | |           Y dS # t          $ r}t          d|  d|           |d}~ww xY ww xY w)zTry to make a hard link from src to dst and if that fails
    copy the file. Hard links save some disk space and linking
    should fail fast since no copying is involved.
    r   zCopying z -> zerror copying N)r   r   linkAttributeErrorr'   shutilcopyr	   )rR   rS   rT   r*   s       r   link_or_copyrZ   ~   s    
 1}}*C**S**+++H
SG$ H H H	HKS!!!!!! 	H 	H 	H=s====>>CG	HHs'   4 BA
B(A>>BBc                     	 t          j                    }n+# t          $ r}t          d|            d}Y d}~nd}~ww xY wt          j        |            |S )zRemember and return current directory before calling os.chdir().
    If the current directory could not be determined, return None.
    z)could not get current working directory: N)r   getcwdr'   r   chdir)r>   olddirr*   s      r   r]   r]      sp       EEEFFF HYMs    
>9>funcc                 >    t          | dt          |                     S )zGet function name.__name__)getattrrepr)r_   s    r   funcnamerd      s    4T$ZZ000r   r   excc           	      \    t          dt          |            d| d|d                     dS )'Error log function for shutil.rmtree().	Error in (): r   Nr   rd   )r_   r   re   s      r   rmtree_log_errorrl      s9    <(4..<<4<<CF<<=====r   c                 P    t          dt          |            d| d|            dS )rg   rh   ri   rj   Nrk   )r_   r   excinfos      r   rmtree_log_excro      s5    =(4..==4==G==>>>>>r   c                     t          |            t          j        dk    rt          j        | t
                     dS t          j        | t                     dS )zSRemove given path recursively with shutil.rmtree().
    Errors will be logged.
    )      r   finalr   )onexconerrorN)make_user_readablesysversion_inforX   rmtreero   rl   )r   s    r   rz   rz      sX     t
111d.111111d$4555555r   c                 |    t           j                            |           st          | t          j                   dS dS )z,Make file user readable if it is not a link.N)r   r   islinkr+   statS_IRUSRr   s    r   make_file_readabler      s:    7>>(## )4<((((() )r   c                 T    t          | t          j        t          j        z             dS )z,Make directory user readable and executable.N)r+   r}   r~   S_IXUSRr   s    r   make_dir_readabler      s!    Xt|dl233333r   c                    t          j        | t                    D ]j\  }}}|D ]/}t          t           j                            ||                     0|D ]/}t          t           j                            ||                     0kdS )z[Make all files in given directory user readable. Also recurse into
    subdirectories.
    ru   N)r   walkr   r   r   rB   r   )r>   rootdirsfilesr
   dirnames         r   rw   rw      s      WY	BBB ; ;dE 	= 	=Hrw||D(;;<<<< 	; 	;Gbgll499::::	;; ;r   )T)Nr/   )r3   )r   )&__doc__r   rx   rX   r}   r5   collections.abcr   r   logr   r   r   utilr	   strboolr   r   r   r"   intr+   r.   r7   r=   rF   rO   rM   rZ   r]   rd   rl   ro   rz   r   r   rw    r   r   <module>r      s   , + 				 



    . . . . . . . . 1 1 1 1 1 1 1 1 1 1      9 9c 9d 9d 9 9 9 9@c @d @ @ @ @J J J J J J;hsm ; ; ; ; ;Ms M3 M4 M M M M%3 %3 % % % %
? ?d
 ?3 ?s ? ? ? ?
	s 	s 	 	 	 	 #   S    
2C 
2C 
2D 
2 
2 
2 
2F F F F F F F
H Hc H H HD H H H H 
S 
S4Z 
 
 
 
18 1 1 1 1 1
>8 >3 >S >T > > > >
? ? ?$ ? ? ? ?
6 6 6 6 6 6) ) ) ) ) )4 4 4 4 4 4
;# ;$ ; ; ; ; ; ;r   