
    OOId'                        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
mZmZmZ d dlmZ d dlmZ  ej        d          Z G d de          Zd	d
d
efdZd Zedk    rd dlZ eej        dd                    dS dS )    N)EIOENOENT)FUSEFuseOSErrorLoggingMixIn
Operations)__version__)	url_to_fsfsspec.fusec                   d    e Zd ZddZddZd Zd Zd Zd Zd	 Z	dd
Z
d ZddZd Zd Zd ZdS )FUSErFc                     || _         i | _        |                    d          dz   | _        d| _        t
                              d|           || _        d S )N/r   zStarting FUSE at %s)fscacherstriprootcounterloggerinfo_ready_file)selfr   path
ready_files       +lib/python3.11/site-packages/fsspec/fuse.py__init__zFUSEr.__init__   sR    
KK$$s*	)4000%    Nc                 N   t                               d|           | j        r	|dv rdddS d                    | j        |                    d          g                              d          }	 | j                            |          }n"# t          $ r t          t                    w xY w|                    dd	          |                    d
d	          d}|                    dd          }|d         dk    rt          j        |z  |d<   d|d<   d|d<   n't          j        |z  |d<   |d         |d<   d|d<   d|d<   d|v r|d         nt!          j                    |d<   d|v r|d         nt!          j                    |d<   d|v r|d         nt!          j                    |d<   |S )Nz
getattr %sz/.fuse_readyz.fuse_readyfile   )typest_size r   uidi  gid)st_uidst_gidmodei  r"   st_moder   r#   
st_blksizesizei  P    st_nlinkatimest_atimectimest_ctimemtimest_mtime)r   debugr   joinr   lstripr   r   r   FileNotFoundErrorr   r   getstatS_IFDIRS_IFREGtime)r   r   fhr   dataperms         r   getattrzFUSEr.getattr   s   \4((( 	2(G G G"q111ww	4;;s#3#3455<<SAA	&7<<%%DD  	& 	& 	&f%%%	& ((5$//488E4;P;PQQxx&&<6!!"lT1DODO!"D"lT1DO"6lDO!*D D,3tOO4==Z,3tOO4==Z,3tOO4==Zs   /B
 
B)c                     t                               d|           d                    | j        |                    d          g          }| j                            |d          }d |D             }ddg|z   S )Nz
readdir %sr$   r   Fc                 r    g | ]4}t           j                            |                    d                     5S )r   )osr   basenamer   ).0fs     r   
<listcomp>z!FUSEr.readdir.<locals>.<listcomp>:   s2    @@@Q!!!((3--00@@@r   .z..)r   r5   r6   r   r7   r   ls)r   r   r>   filess       r   readdirzFUSEr.readdir6   sq    \4(((ww	4;;s#3#3455

4''@@%@@@T{U""r   c                     d                     | j        |                    d          g          }| j                            |           dS Nr$   r   r   )r6   r   r7   r   mkdirr   r   r)   s      r   rO   zFUSEr.mkdir=   ?    ww	4;;s#3#3455dqr   c                     d                     | j        |                    d          g          }| j                            |           dS rN   )r6   r   r7   r   rmdir)r   r   s     r   rS   zFUSEr.rmdirB   rQ   r   c                     t                               d|||f           | j        r|dv rdS | j        |         }|                    |           |                    |          }|S )Nzread %sr   s   ready)r   r5   r   r   seekread)r   r   r,   offsetr>   rG   outs          r   rV   z
FUSEr.readG   sf    YtV 4555 	(G G G8JrN	vffTll
r   c                     t                               d||f           | j        |         }|                    |           |                    |           t          |          S )Nzwrite %s)r   r5   r   rU   writelen)r   r   r?   rW   r>   rG   s         r   rZ   zFUSEr.writeR   sO    Z$000JrN	v	4yyr   c                 V   t                               d||f           d                    | j        |                    d          g          }| j                            |           | j                            |d          }|| j        | j	        <   | xj	        dz  c_	        | j	        dz
  S )Nz	create %sr$   r   wbr-   )
r   r5   r6   r   r7   r   touchopenr   r   )r   r   flagsfifnrG   s         r   createzFUSEr.createY   s    [4-000WWdiS!1!1233bGLLT""#$
4< |ar   c                 :   t                               d||f           d                    | j        |                    d          g          }|dz  dk    rd}nd}| j                            ||          | j        | j        <   | xj        dz  c_        | j        dz
  S )	Nzopen %sr$   r      r   rbr]   r-   )	r   r5   r6   r   r7   r   r_   r   r   )r   r   r`   rb   r)   s        r   r_   z
FUSEr.openb   s    Yu...WWdiS!1!123319>>DD D#'7<<D#9#9
4< |ar   c                     d                     | j        |                    d          g          }|dk    rt          | j                            |           d S rN   )r6   r   r7   NotImplementedErrorr   r^   )r   r   lengthr>   rb   s        r   truncatezFUSEr.truncateo   sO    WWdiS!1!1233Q;;%%br   c                     d                     | j        |                    d          g          }	 | j                            |d           d S # t
          t          f$ r t          t                    w xY w)Nr$   r   F)	r6   r   r7   r   rmIOErrorr8   r   r   )r   r   rb   s      r   unlinkzFUSEr.unlinkv   sv    WWdiS!1!1233	#GJJr5!!!!!*+ 	# 	# 	#c"""	#s   A &A4c                     	 || j         v r;| j         |         }|                                 | j                             |           n&# t          $ r}t	          |           Y d }~nd }~ww xY wdS )Nr   )r   closepop	Exceptionprint)r   r   r>   rG   es        r   releasezFUSEr.release}   sz    	TZJrN			
r""" 	 	 	!HHHHHHHH	qs   AA 
A*A%%A*c                     t          | j        d          rJd                    | j        |                    d          g          }| j                            ||          S t          )Nchmodr$   r   )hasattrr   r6   r   r7   rw   rh   rP   s      r   rw   zFUSEr.chmod   sV    47G$$ 	-77DIt{{3'7'7899D7==t,,,!!r   )F)N)__name__
__module____qualname__r   rA   rL   rO   rS   rV   rZ   rc   r_   rj   rn   ru   rw    r   r   r   r      s        & & & &   8# # #  
  
	 	 	                 # # #  " " " " "r   r   TFc                       fd}s2t          j        |          }d|_        |                                 |S 	  |             dS # t          $ r Y dS w xY w)am  Mount stuff in a local directory

    This uses fusepy to make it appear as if a given path on an fsspec
    instance is in fact resident within the local file-system.

    This requires that fusepy by installed, and that FUSE be available on
    the system (typically requiring a package to be installed with
    apt, yum, brew, etc.).

    Parameters
    ----------
    fs: file-system instance
        From one of the compatible implementations
    path: str
        Location on that file-system to regard as the root directory to
        mount. Note that you typically should include the terminating "/"
        character.
    mount_point: str
        An empty directory on the local file-system where the contents of
        the remote path will appear.
    foreground: bool
        Whether or not calling this function will block. Operation will
        typically be more stable if True.
    threads: bool
        Whether or not to create threads when responding to file operations
        within the mounter directory. Operation will typically be more
        stable if False.
    ready_file: bool
        Whether the FUSE process is ready. The ``.fuse_ready`` file will
        exist in the ``mount_point`` directory if True. Debugging purpose.
    ops_class: FUSEr or Subclass of FUSEr
        To override the default behavior of FUSEr. For Example, logging
        to file.

    c                  D    t                                 S )N)r   )	nothreads
foreground)r   )r   r   mount_point	ops_classr   r   threadss   r   <lambda>zrun.<locals>.<lambda>   s5    4	"dz222+	   r   )targetTN)	threadingThreaddaemonstartKeyboardInterrupt)	r   r   r   r   r   r   r   funcths	   ```````  r   runr      s    X         D  	T***	



		DFFFFF  	 	 	DD	s   
A 
A"!A"c           	          G fddt           j                   dt          j                  }|                    ddt
                     |                    dt          d	
           |                    dt          d
           |                    dt          d
           |                    dddd           |                    ddt          d
           |                    dddd           |                    dddd           |                    dddd            |                    |           } i }| j        pg D ]}|	                    d!          \  }}}|s)|
                    d"                    |          #           |                                }|                    d$          r&t          |d%t          d$                              }n/|                    d&          r|d%t          d&                    d'v }d(|v r1|                    d(d)          \  }}	||v r|||         |	<   |	|i||<   |||<   | j        rBt%          j        t$          j        | j        d*+            G d, d-t*          t,                    }
|
}nt*          }t/          | j        fi |\  }}t2                              d.|t          | j                             t9          || j        | j        | j        | j        | j         |/           d%S )0a  Mount filesystem from chained URL to MOUNT_POINT.

    Examples:

    python3 -m fsspec.fuse memory /usr/share /tmp/mem

    python3 -m fsspec.fuse local /tmp/source /tmp/local \
            -l /tmp/fsspecfuse.log

    You can also mount chained-URLs and use special settings:

    python3 -m fsspec.fuse 'filecache::zip::file://data.zip' \
            / /tmp/zip \
            -o 'filecache-cache_storage=/tmp/simplecache'

    You can specify the type of the setting by using `[int]` or `[bool]`,
    (`true`, `yes`, `1` represents the Boolean value `True`):

    python3 -m fsspec.fuse 'simplecache::ftp://ftp1.at.proftpd.org' \
            /historic/packages/RPMS /tmp/ftp \
            -o 'simplecache-cache_storage=/tmp/simplecache' \
            -o 'simplecache-check_files=false[bool]' \
            -o 'ftp-listings_expiry_time=60[int]' \
            -o 'ftp-username=anonymous' \
            -o 'ftp-password=xieyanbo'
    c                   "     e Zd Z fdZ xZS )*main.<locals>.RawDescriptionArgumentParserc                     t          |                                           }|                    d          }| j                                        |d<   d                    |          S )Nz

r-   )superformat_helpsplitdescriptionr   r6   )r   usagepartsRawDescriptionArgumentParser	__class__s      r   r   z6main.<locals>.RawDescriptionArgumentParser.format_help   sZ    6==IIKKEKK''E'..00E!H;;u%%%r   )ry   rz   r{   r   __classcell__)r   r   s   @r   r   r      s>        	& 	& 	& 	& 	& 	& 	& 	& 	& 	&r   r   r   )progr   z	--versionversion)actionr   urlzfs url)r"   helpsource_pathzsource directory in fsr   zlocal directoryz-oz--optionappendz3Any options of protocol included in the chained URL)r   r   z-lz
--log-filez%Logging FUSE debug info (Default: '')z-fz--foregroundstore_falsez-Running in foreground or not (Default: False)z-tz	--threadsz-Running with threads support (Default: False)z-rz--ready-filezZThe `.fuse_ready` file will exist after FUSE is ready. (Debugging purpose, Default: False)=zWrong option: {!r})messagez[int]Nz[bool])1yestrue-r-   z%(asctime)s %(message)s)levelfilenameformatc                       e Zd ZdS )main.<locals>.LoggingFUSErN)ry   rz   r{   r|   r   r   LoggingFUSErr   -  s        Dr   r   zMounting %s to %s)r   r   r   r   )!argparseArgumentParsermain__doc__add_argumentr	   str
parse_argsoption	partitionerrorr   lowerendswithintr[   r   log_fileloggingbasicConfigDEBUGr   r   r
   r   r   r5   r   r   r   r   r   r   )argsparserkwargsitemkeysepvaluevalfs_namesetting_namer   fuserr   url_pathr   s                 @r   r   r      s   8& & & & & & &x'> & & & *)}$,WWWF
I{KKK
Ch777
C6NOOO
C6GHHH
B	     l+R     <	     <	     .	     T""DF!r    ..--S% 	DLL!5!<!<T!B!BLCCCkkmm<<   	BoWo.//EE\\(## 	B(3x==.()-AAE#::$'IIc1$5$5!G\&  05w--#/"7wF3KK} -],	
 	
 	
 	
	 	 	 	 	5, 	 	 	 TX0000LB
LL$hD4D0E0EFFF
??     r   __main__r-   )r   r   rD   r:   r   r=   errnor   r   fuser   r   r   r   fsspecr	   fsspec.corer
   	getLoggerr   r   r   r   ry   sysargvr|   r   r   <module>r      sW     				               < < < < < < < < < < < <       ! ! ! ! ! !		=	)	)z" z" z" z" z"J z" z" z"B ; ; ; ;|r r rj zJJJD!"" r   