U
    9%e'                     @   s   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dZG dd deZd	d
d
efddZdd Zedkrd dlZeejdd  dS )    N)EIOENOENT)FUSEFuseOSErrorLoggingMixIn
Operations)__version__)	url_to_fsfsspec.fusec                   @   s|   e Zd ZdddZdddZdd Zd	d
 Zdd Zdd Zdd Z	dddZ
dd Zd ddZdd Zdd Zdd ZdS )!FUSErFc                 C   s8   || _ i | _|dd | _d| _td| || _d S )N/r   zStarting FUSE at %s)fscacherstriprootcounterloggerinfo_ready_file)selfr   path
ready_file r   J/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/fsspec/fuse.py__init__   s    zFUSEr.__init__Nc                 C   sF  t d| | jr$|dkr$dddS d| j|dgd}z| j|}W n t	k
rl   t
tY nX |dd	|d
d	d}|dd}|d dkrtj|B |d< d|d< d|d< n*tj|B |d< |d |d< d|d< d|d< d|kr|d nt |d< d|kr|d nt |d< d|kr6|d nt |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permr   r   r   getattr   s,    

zFUSEr.getattrc                 C   sJ   t d| d| j|dg}| j|d}dd |D }ddg| S )	Nz
readdir %sr    r   Fc                 S   s   g | ]}t j|d qS )r   )osr   basenamer   ).0fr   r   r   
<listcomp>:   s     z!FUSEr.readdir.<locals>.<listcomp>.z..)r   r1   r2   r   r3   r   Zls)r   r   r:   filesr   r   r   readdir6   s
    zFUSEr.readdirc                 C   s&   d | j|dg}| j| dS Nr    r   r   )r2   r   r3   r   mkdirr   r   r%   r   r   r   rG   =   s    zFUSEr.mkdirc                 C   s&   d | j|dg}| j| dS rF   )r2   r   r3   r   rmdir)r   r   r   r   r   rI   B   s    zFUSEr.rmdirc                 C   sF   t d|||f | jr$|dkr$dS | j| }|| ||}|S )Nzread %sr   s   ready)r   r1   r   r   seekread)r   r   r(   offsetr:   rA   outr   r   r   rK   G   s    


z
FUSEr.readc                 C   s6   t d||f | j| }|| || t|S )Nzwrite %s)r   r1   r   rJ   writelen)r   r   r;   rL   r:   rA   r   r   r   rN   R   s
    


zFUSEr.writec                 C   sd   t d||f d| j|dg}| j| | j|d}|| j| j	< |  j	d7  _	| j	d S )Nz	create %sr    r   wbr)   )
r   r1   r2   r   r3   r   touchopenr   r   )r   r   flagsfifnrA   r   r   r   createY   s    zFUSEr.createc                 C   sj   t d||f d| j|dg}|d dkr8d}nd}| j||| j| j< |  jd7  _| jd S )	Nzopen %sr    r      r   rbrP   r)   )	r   r1   r2   r   r3   r   rR   r   r   )r   r   rS   rU   r%   r   r   r   rR   b   s    z
FUSEr.openc                 C   s2   d | j|dg}|dkr"t| j| d S rF   )r2   r   r3   NotImplementedErrorr   rQ   )r   r   lengthr:   rU   r   r   r   truncateo   s    zFUSEr.truncatec              	   C   sN   d | j|dg}z| j|d W n  ttfk
rH   ttY nX d S )Nr    r   F)	r2   r   r3   r   ZrmOSErrorr4   r   r   )r   r   rU   r   r   r   unlinkv   s
    zFUSEr.unlinkc              
   C   s\   z,|| j kr*| j | }|  | j | W n* tk
rV } zt| W 5 d }~X Y nX dS )Nr   )r   closepop	Exceptionprint)r   r   r:   rA   er   r   r   release}   s    

zFUSEr.releasec                 C   s8   t | jdr0d| j|dg}| j||S td S )Nchmodr    r   )hasattrr   r2   r   r3   rd   rY   rH   r   r   r   rd      s    zFUSEr.chmod)F)N)N)N)__name__
__module____qualname__r   r=   rE   rG   rI   rK   rN   rV   rR   r[   r]   rc   rd   r   r   r   r   r      s   


	

r   TFc           	         s^    fdd} s:t j|d}d|_|  |S z
|  W n tk
rX   Y nX dS )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                      s   t d  dS )N)r   )Z	nothreads
foreground)r   r   ri   r   mount_point	ops_classr   r   threadsr   r   <lambda>   s
   zrun.<locals>.<lambda>)targetTN)	threadingThreaddaemonstartKeyboardInterrupt)	r   r   rk   ri   rm   r   rl   functhr   rj   r   run   s    ,
rw   c              	      s  G  fdddt j  dtjd}|jddtd |jdtd	d
 |jdtdd
 |jdtdd
 |jddddd |jddtdd
 |jddddd |jddddd |jdddd d || } i }| jpg D ]}|	d!\}}}|s|j
d"|d# | }|d$r.t|d%td$  }n"|d&rP|d%td&  d'k}d(|kr|d(d)\}}	||kr||| |	< n|	|i||< q|||< q| jrtjtj| jd*d+ G d,d- d-tt}
|
}nt}t| jf|\}}td.|t| j t|| j| j| j| j| j |d/ 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                       s   e Zd Z fddZ  ZS )z*main.<locals>.RawDescriptionArgumentParserc                    s0   t  |  }|d}| j |d< d|S )Nz

r)   )superformat_helpsplitdescriptionr   r2   )r   usageparts)RawDescriptionArgumentParser	__class__r   r   ry      s    
z6main.<locals>.RawDescriptionArgumentParser.format_help)rf   rg   rh   ry   __classcell__r   r~   )r   r   r~      s   r~   r
   )progr{   z	--versionversion)actionr   urlzfs url)r   helpsource_pathzsource directory in fsrk   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                   @   s   e Zd ZdS )zmain.<locals>.LoggingFUSErN)rf   rg   rh   r   r   r   r   LoggingFUSEr-  s   r   zMounting %s to %s)ri   rm   r   rl   )!argparseArgumentParsermain__doc__add_argumentr   str
parse_argsoption	partitionerrorr   lowerendswithintrO   rz   Zlog_fileloggingbasicConfigDEBUGr   r   r	   r   r   r1   rk   rw   r   ri   rm   r   )argsparserkwargsitemkeysepvaluevalZfs_nameZsetting_namer   Zfuserr   Zurl_pathr   r   r   r      s       



r   __main__r)   )r   r   r>   r6   rp   r9   errnor   r   Zfuser   r   r   r   Zfsspecr   Zfsspec.corer	   	getLoggerr   r   rw   r   rf   sysargvr   r   r   r   <module>   s*   
 
>u