a
    $lJh5#                     @  s   d Z ddlmZ ddlZddlZddlZddlmZ ddlm	Z	m
Z
 ddlmZ G dd	 d	eZedd
ddddZedd
ddddZedd
ddddZedd
ddddZedd
ddddZedd
ddddZd	gZdS )zAndroid.    )annotationsN)	lru_cache)TYPE_CHECKINGcast   )PlatformDirsABCc                   @  s0  e Zd ZdZeddddZeddddZedddd	Zeddd
dZeddddZ	eddddZ
eddddZeddddZeddddZeddddZeddddZeddddZeddddZeddddZeddd d!Zeddd"d#Zd$S )%Androida"  
    Follows the guidance `from here <https://android.stackexchange.com/a/216132>`_.

    Makes use of the `appname <platformdirs.api.PlatformDirsABC.appname>`, `version
    <platformdirs.api.PlatformDirsABC.version>`, `ensure_exists <platformdirs.api.PlatformDirsABC.ensure_exists>`.

    strreturnc                 C  s   |  tdt dS )zd:return: data directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/files/<AppName>``r	   filesZ_append_app_name_and_versionr   _android_folderself r   R/var/www/shaz/venv/lib/python3.9/site-packages/pip/_vendor/platformdirs/android.pyuser_data_dir   s    zAndroid.user_data_dirc                 C  s   | j S )z@:return: data directory shared by users, same as `user_data_dir`r   r   r   r   r   site_data_dir   s    zAndroid.site_data_dirc                 C  s   |  tdt dS )z
        :return: config directory tied to the user, e.g.         ``/data/user/<userid>/<packagename>/shared_prefs/<AppName>``
        r	   Zshared_prefsr   r   r   r   r   user_config_dir!   s    zAndroid.user_config_dirc                 C  s   | j S )zH:return: config directory shared by the users, same as `user_config_dir`)r   r   r   r   r   site_config_dir)   s    zAndroid.site_config_dirc                 C  s   |  tdt dS )ze:return: cache directory tied to the user, e.g.,``/data/user/<userid>/<packagename>/cache/<AppName>``r	   cacher   r   r   r   r   user_cache_dir.   s    zAndroid.user_cache_dirc                 C  s   | j S )zB:return: cache directory shared by users, same as `user_cache_dir`)r   r   r   r   r   site_cache_dir3   s    zAndroid.site_cache_dirc                 C  s   | j S )zB:return: state directory tied to the user, same as `user_data_dir`r   r   r   r   r   user_state_dir8   s    zAndroid.user_state_dirc                 C  s   | j }| jrtj|d}|S )z
        :return: log directory tied to the user, same as `user_cache_dir` if not opinionated else ``log`` in it,
          e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>/log``
        logr   opinionospathjoinr   r    r   r   r   user_log_dir=   s    zAndroid.user_log_dirc                 C  s   t  S )zT:return: documents directory tied to the user e.g. ``/storage/emulated/0/Documents``)_android_documents_folderr   r   r   r   user_documents_dirH   s    zAndroid.user_documents_dirc                 C  s   t  S )zT:return: downloads directory tied to the user e.g. ``/storage/emulated/0/Downloads``)_android_downloads_folderr   r   r   r   user_downloads_dirM   s    zAndroid.user_downloads_dirc                 C  s   t  S )zR:return: pictures directory tied to the user e.g. ``/storage/emulated/0/Pictures``)_android_pictures_folderr   r   r   r   user_pictures_dirR   s    zAndroid.user_pictures_dirc                 C  s   t  S )zS:return: videos directory tied to the user e.g. ``/storage/emulated/0/DCIM/Camera``)_android_videos_folderr   r   r   r   user_videos_dirW   s    zAndroid.user_videos_dirc                 C  s   t  S )zL:return: music directory tied to the user e.g. ``/storage/emulated/0/Music``)_android_music_folderr   r   r   r   user_music_dir\   s    zAndroid.user_music_dirc                 C  s   dS )zP:return: desktop directory tied to the user e.g. ``/storage/emulated/0/Desktop``z/storage/emulated/0/Desktopr   r   r   r   r   user_desktop_dira   s    zAndroid.user_desktop_dirc                 C  s   | j }| jrtj|d}|S )z
        :return: runtime directory tied to the user, same as `user_cache_dir` if not opinionated else ``tmp`` in it,
          e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>/tmp``
        tmpr   r"   r   r   r   user_runtime_dirf   s    zAndroid.user_runtime_dirc                 C  s   | j S )zF:return: runtime directory shared by users, same as `user_runtime_dir`)r0   r   r   r   r   site_runtime_dirq   s    zAndroid.site_runtime_dirN)__name__
__module____qualname____doc__propertyr   r   r   r   r   r   r   r#   r%   r'   r)   r+   r-   r.   r0   r1   r   r   r   r   r      sB   

r   )maxsizez
str | Noner
   c                  C  s  d} t sNz.ddlm} td| }|   } W n tyL   d} Y n0 | du rz(ddl	m
} |d}|   } W n ty   d} Y n0 | du rtd}tjD ] }||r|dd }  qqd} | du rtd}tjD ]"}||r|dd }  qqd} | S )	zE:return: base folder for the Android OS or None if it cannot be foundNr   )	mActivityandroid.content.Context	autoclassz /data/(data|user/\d+)/(.+)/filesz/filesz7/mnt/expand/[a-fA-F0-9-]{36}/(data|user/\d+)/(.+)/files)r   Zandroidr8   r   ZgetApplicationContextZgetFilesDirZgetParentFilegetAbsolutePath	Exceptionjniusr;   recompilesysr    matchsplit)resultr8   contextr;   patternr    r   r   r   r   w   s<    








r   r	   c                  C  sL   z0ddl m}  | d}| d}||j }W n tyF   d}Y n0 |S )z,:return: documents folder for the Android OSr   r:   r9   android.os.Environmentz/storage/emulated/0/Documents)r>   r;   getExternalFilesDirZDIRECTORY_DOCUMENTSr<   r=   )r;   rE   environmentZdocuments_dirr   r   r   r$      s    
r$   c                  C  sL   z0ddl m}  | d}| d}||j }W n tyF   d}Y n0 |S )z,:return: downloads folder for the Android OSr   r:   r9   rG   z/storage/emulated/0/Downloads)r>   r;   rH   ZDIRECTORY_DOWNLOADSr<   r=   )r;   rE   rI   Zdownloads_dirr   r   r   r&      s    
r&   c                  C  sL   z0ddl m}  | d}| d}||j }W n tyF   d}Y n0 |S )z+:return: pictures folder for the Android OSr   r:   r9   rG   z/storage/emulated/0/Pictures)r>   r;   rH   ZDIRECTORY_PICTURESr<   r=   )r;   rE   rI   Zpictures_dirr   r   r   r(      s    
r(   c                  C  sL   z0ddl m}  | d}| d}||j }W n tyF   d}Y n0 |S )z):return: videos folder for the Android OSr   r:   r9   rG   z/storage/emulated/0/DCIM/Camera)r>   r;   rH   ZDIRECTORY_DCIMr<   r=   )r;   rE   rI   Z
videos_dirr   r   r   r*      s    
r*   c                  C  sL   z0ddl m}  | d}| d}||j }W n tyF   d}Y n0 |S )z(:return: music folder for the Android OSr   r:   r9   rG   z/storage/emulated/0/Music)r>   r;   rH   ZDIRECTORY_MUSICr<   r=   )r;   rE   rI   Z	music_dirr   r   r   r,      s    
r,   )r5   
__future__r   r   r?   rA   	functoolsr   typingr   r   apir   r   r   r$   r&   r(   r*   r,   __all__r   r   r   r   <module>   s,   i/