
    g'                        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j2                  dd        yy)    N)EIOENOENT)FUSEFuseOSErrorLoggingMixIn
Operations)__version__)	url_to_fsfsspec.fusec                   b    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y)FUSErc                     || _         i | _        |j                  d      dz   | _        d| _        t
        j                  d|       || _        y )N/r   zStarting FUSE at %s)fscacherstriprootcounterloggerinfo_ready_file)selfr   path
ready_files       @/var/www/openai/venv/lib/python3.12/site-packages/fsspec/fuse.py__init__zFUSEr.__init__   sC    
KK$s*	)40%    Nc                    t         j                  d|       | j                  r	|dv rdddS dj                  | j                  |j                  d      g      j                  d      }	 | j                  j                  |      }|j                  dd	      |j                  d
d	      d}|j                  dd      }|d   dk7  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 # t        $ r}t        t              |d }~ww xY w)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   excdataperms          r   getattrzFUSEr.getattr   s|   \4((G G"q11ww		4;;s#345<<SA	/77<<%D ((5$/488E4;PQxx&<6!"llT1DODO!"D"llT1DO"6lDO!*D D,3tO4=Z,3tO4=Z,3tO4=Z% ! 	/f%3.	/s   (E- -	F6FFc                 L   t         j                  d|       dj                  | j                  |j	                  d      g      }| j
                  j                  |d      }|D cg c]0  }t        j                  j                  |j                  d            2 }}ddg|z   S c c}w )Nz
readdir %sr$   r   F.z..)r   r5   r6   r   r7   r   lsosr   basenamer   )r   r   r>   filesfs        r   readdirzFUSEr.readdir6   s    \4(ww		4;;s#345

4':?@%Q!!!((3-0%@T{U"" As   #5B!c                     dj                  | j                  |j                  d      g      }| j                  j	                  |       yNr$   r   r   )r6   r   r7   r   mkdirr   r   r)   s      r   rM   zFUSEr.mkdir=   5    ww		4;;s#345dr   c                     dj                  | j                  |j                  d      g      }| j                  j	                  |       yrL   )r6   r   r7   r   rmdir)r   r   s     r   rQ   zFUSEr.rmdirB   rO   r   c                     t         j                  d|||f       | j                  r|dv ry| j                  |   }|j	                  |       |j                  |      }|S )Nzread %sr   s   ready)r   r5   r   r   seekread)r   r   r,   offsetr>   rI   outs          r   rT   z
FUSEr.readG   sU    YtV 45(G GJJrN	vffTl
r   c                     t         j                  d||f       | j                  |   }|j                  |       |j	                  |       t        |      S )Nzwrite %s)r   r5   r   rS   writelen)r   r   r@   rU   r>   rI   s         r   rX   zFUSEr.writeR   sA    Z$0JJrN	v	4yr   c                 r   t         j                  d||f       dj                  | j                  |j	                  d      g      }| j
                  j                  |       | 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fnrI   s         r   createzFUSEr.createY   s    [4-0WWdiiS!123bGGLLT"#$

4<< ||ar   c                 R   t         j                  d||f       dj                  | j                  |j	                  d      g      }|dz  dk(  rd}nd}| j
                  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^   r`   r)   s        r   r]   z
FUSEr.openb   s    Yu.WWdiiS!12319>D D#'77<<D#9

4<< ||ar   c                     dj                  | j                  |j                  d      g      }|dk7  rt        | j                  j                  |       y rL   )r6   r   r7   NotImplementedErrorr   r\   )r   r   lengthr>   r`   s        r   truncatezFUSEr.truncateo   s?    WWdiiS!123Q;%%br   c                     dj                  | j                  |j                  d      g      }	 | j                  j	                  |d       y # t
        t        f$ r}t        t              |d }~ww xY w)Nr$   r   F)	r6   r   r7   r   rmOSErrorr8   r   r   )r   r   r`   r?   s       r   unlinkzFUSEr.unlinkv   s\    WWdiiS!123	,GGJJr5!*+ 	,c"+	,s   A A/A**A/c                     	 || j                   v r:| j                   |   }|j                          | j                   j                  |       y# t        $ r}t	        |       Y d }~yd }~ww xY w)Nr   )r   closepop	Exceptionprint)r   r   r>   rI   es        r   releasezFUSEr.release}   s\    	TZZJJrN	

r"   	!HH	s   AA 	A)A$$A)c                     t        | j                  d      rHdj                  | j                  |j	                  d      g      }| j                  j                  ||      S t        )Nchmodr$   r   )hasattrr   r6   r   r7   ru   rf   rN   s      r   ru   zFUSEr.chmod   sK    477G$77DIIt{{3'789D77==t,,!!r   )F)N)__name__
__module____qualname__r   rB   rJ   rM   rQ   rT   rX   ra   r]   rh   rl   rs   ru    r   r   r   r      sC    &8#

	  ,"r   r   TFc                       fd}s/t        j                  |      }d|_        |j                          |S 	  |        y# t        $ r Y y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                  6    t                       S )N)r   )	nothreads
foreground)r   )r~   r   mount_point	ops_classr   r   threadss   r   <lambda>zrun.<locals>.<lambda>   s!    4"dz2+	r   )targetTN)	threadingThreaddaemonstartKeyboardInterrupt)	r   r   r   r~   r   r   r   funcths	   ```````  r   runr      sV    X D T*	

		F  		s   A 	AAc           	          G d dt         j                        } |dt        j                        }|j	                  ddt
               |j	                  dt        d	
       |j	                  dt        d
       |j	                  dt        d
       |j	                  dddd       |j	                  ddt        d
       |j	                  dddd       |j	                  dddd       |j	                  dddd        |j                  |       } i }| j                  xs g D ]  }|j                  d!      \  }}}|s|j                  d"|#       |j                         }|j                  d$      rt        |d%t        d$              }n"|j                  d&      r|d%t        d&        d'v }d(|v r*|j                  d(d)      \  }	}
|	|v r	|||	   |
<   |
|i||	<   |||<    | j                   rGt#        j$                  t"        j&                  | j                   d*+        G d, d-t(        t*              }|}nt(        }t-        | j.                  fi |\  }}t0        j3                  d.|t        | j4                               t7        || j8                  | j4                  | j:                  | j<                  | j>                  |/       y%)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         |          }|j                  d      }| j                  j	                         |d<   dj                  |      S )Nz

r-   )superformat_helpsplitdescriptionr   r6   )r   usageparts	__class__s      r   r   z6main.<locals>.RawDescriptionArgumentParser.format_help   sE    G')EKK'E''..0E!H;;u%%r   )rw   rx   ry   r   __classcell__)r   s   @r   RawDescriptionArgumentParserr      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: )messagez[int]Nz[bool])1yestrue-r-   z%(asctime)s %(message)s)levelfilenameformatc                       e Zd Zy)main.<locals>.LoggingFUSErN)rw   rx   ry   rz   r   r   LoggingFUSErr   -  s    r   r   zMounting %s to %s)r~   r   r   r   ) argparseArgumentParsermain__doc__add_argumentr	   str
parse_argsoption	partitionerrorlowerendswithintrY   r   log_fileloggingbasicConfigDEBUGr   r   r
   r   r   r5   r   r   r   r~   r   r   )argsr   parserkwargsitemkeysepvaluevalfs_namesetting_namer   fuserr   url_paths                  r   r   r      s   8&x'>'> & *}$,,WF
I{K
Ch7
C6NO
C6GH
B	   l+R   <	   <	   .	   T"DF!r!..-S%LL>$!:L;kkm<< oW./E\\(#(3x=.)-AAE#:$'IIc1$5!G\& 05w-#/"7wF3K# "& }}--]],	
	5, 	 TXX00LB
LL$hD4D4D0EF
????r   __main__r-   )r   r   rF   r:   r   r=   errnor   r   fuser   r   r   r   fsspecr	   fsspec.corer
   	getLoggerr   r   r   r   rw   sysargvrz   r   r   <module>r      s      	     < <  !			=	)z"J z"B ;|rj z!" r   