U
    -e=                     @   s   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
 G dd de
jeZdd Zdd	 Zd
d Zdd ZdddZdddZdS )    N)doc	_DEPR_MSG)
FileSystemc                       s   e Zd ZdZdddZdd	 Zd
d Zeej	 fddZ	eej
 fddZ
eejd fdd	Z fddZeej fddZeej fddZd fdd	Zdd Z  ZS ) HadoopFileSystema  
    DEPRECATED: FileSystem interface for HDFS cluster.

    See pyarrow.hdfs.connect for full connection details

    .. deprecated:: 2.0
        ``pyarrow.hdfs.HadoopFileSystem`` is deprecated,
        please use ``pyarrow.fs.HadoopFileSystem`` instead.
    defaultr   Nlibhdfsc                 C   s>   t jtdddtdd |dkr(t  | ||||| d S )Nzhdfs.HadoopFileSystem2.0.0fs.HadoopFileSystem   
stacklevelr   )warningswarnr   formatFutureWarning_maybe_set_hadoop_classpath_connect)selfhostportuserkerb_ticketZdriver
extra_conf r   M/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/pyarrow/hdfs.py__init__(   s       zHadoopFileSystem.__init__c                 C   s   t | j| j| j| j| jffS N)r   r   r   r   r   r   r   r   r   r   
__reduce__3   s     zHadoopFileSystem.__reduce__c                 C   s   dS )zR
        Return True if this is a Unix-style file store with directories.
        Tr   r   r   r   r   _isfilestore7   s    zHadoopFileSystem._isfilestorec                    s   t  |S r   )superisdirr   path	__class__r   r   r!   =   s    zHadoopFileSystem.isdirc                    s   t  |S r   )r    isfiler"   r$   r   r   r&   A   s    zHadoopFileSystem.isfileFc                    s   t  ||S r   )r    delete)r   r#   	recursiver$   r   r   r'   E   s    zHadoopFileSystem.deletec                    s   t  |S )a  
        Create directory in HDFS.

        Parameters
        ----------
        path : str
            Directory path to create, including any parent directories.

        Notes
        -----
        libhdfs does not support create_parents=False, so we ignore this here
        )r    mkdir)r   r#   kwargsr$   r   r   r)   I   s    zHadoopFileSystem.mkdirc                    s   t  ||S r   )r    rename)r   r#   new_pathr$   r   r   r+   X   s    zHadoopFileSystem.renamec                    s   t  |S r   )r    existsr"   r$   r   r   r-   \   s    zHadoopFileSystem.existsc                    s   t  ||S )ap  
        Retrieve directory contents and metadata, if requested.

        Parameters
        ----------
        path : str
            HDFS path to retrieve contents of.
        detail : bool, default False
            If False, only return list of paths.

        Returns
        -------
        result : list of dicts (detail=True) or strings (detail=False)
        )r    ls)r   r#   detailr$   r   r   r.   `   s    zHadoopFileSystem.lsc                 c   sN   | j |dd}t||\}}|||fV  |D ]}| | ||E dH  q,dS )a  
        Directory tree generator for HDFS, like os.walk.

        Parameters
        ----------
        top_path : str
            Root directory for tree traversal.

        Returns
        -------
        Generator yielding 3-tuple (dirpath, dirnames, filename)
        T)r/   N)r.   _libhdfs_walk_files_dirswalk
_path_join)r   top_pathcontentsdirectoriesfilesdirnamer   r   r   r1   q   s
    zHadoopFileSystem.walk)r   r   NNr   N)F)F)__name__
__module____qualname____doc__r   r   r   r   r   r!   r&   r'   r)   r+   r-   r.   r1   __classcell__r   r   r$   r   r      s(   
    
r   c                  C   st   dd l } | dtjddr"d S dtjkrXtjdkr>t }q`dtjd }t	|}nt	d}|
d	tjd< d S )
Nr   zhadoop-common[^/]+.jarZ	CLASSPATH HADOOP_HOMEwin32z{}/bin/hadoopZhadooputf-8)researchosenvirongetsysplatform_derive_hadoop_classpathr   _hadoop_classpath_globdecode)rA   	classpath
hadoop_binr   r   r   r      s    


r   c                  C   s   dd l } ddtjd ddf}| j|| jd}| jd|j| jd	}| jd
|jd}dtjkrdtjd ntjd d }|d d| S )Nr   findz-Lr>   z-namez*.jar)stdout)ZxargsZecho)stdinrN   )trz' 'z':')rO   ZHADOOP_CONF_DIRz/etc/hadoop:r@   )
subprocessrC   rD   PopenPIPErN   check_outputencode)rR   Z	find_argsrM   Z
xargs_echoZjarsZhadoop_confr   r   r   rH      s    rH   c                 C   s   dd l }| ddf}||S )Nr   rK   z--glob)rR   rU   )rL   rR   Zhadoop_classpath_argsr   r   r   rI      s    
rI   c                 C   sN   g }g }|D ]8}t |d d }|d dkr:|| q|| q||fS )Nname   kindfile)	posixpathsplitappend)r3   r4   r6   r5   cZscrubbed_namer   r   r   r0      s    r0   r   c                 C   s,   t jtdddtdd t| ||||dS )a  
    DEPRECATED: Connect to an HDFS cluster.

    All parameters are optional and should only be set if the defaults need
    to be overridden.

    Authentication should be automatic if the HDFS cluster uses Kerberos.
    However, if a username is specified, then the ticket cache will likely
    be required.

    .. deprecated:: 2.0
        ``pyarrow.hdfs.connect`` is deprecated,
        please use ``pyarrow.fs.HadoopFileSystem`` instead.

    Parameters
    ----------
    host : NameNode. Set to "default" for fs.defaultFS from core-site.xml.
    port : NameNode's port. Set to 0 for default or logical (HA) nodes.
    user : Username when connecting to HDFS; None implies login user.
    kerb_ticket : Path to Kerberos ticket cache.
    extra_conf : dict, default None
      extra Key/Value pairs for config; Will override any
      hdfs-site.xml properties

    Notes
    -----
    The first time you call this method, it will take longer than usual due
    to JNI spin-up time.

    Returns
    -------
    filesystem : HadoopFileSystem
    zhdfs.connectr   r	   r
   r   r   r   r   r   r   )r   r   r   r   r   r   r_   r   r   r   connect   s    #    r`   c              	   C   s4   t  " t d t| ||||d}W 5 Q R X |S )Nignorer_   )r   catch_warningssimplefilterr   )r   r   r   r   r   fsr   r   r   r      s    

r   )r   r   NNN)r   r   NNN)rC   r[   rF   r   Zpyarrow.utilr   r   Zpyarrow.filesystemr   Zpyarrow._hdfsioZ_hdfsior   r   rH   rI   r0   r`   r   r   r   r   r   <module>   s"   i  
-  