a
    hbòf¬  ã                   @  s†   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 G dd„ deƒZ	edd�d	d
œdd„ƒZ
edd�d	d
œdd„ƒZdgZdS )é    )ÚannotationsN)Ú	lru_cacheé   )ÚPlatformDirsABCc                   @  s²   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dS )ÚAndroidzá
    Follows the guidance `from here <https://android.stackexchange.com/a/216132>`_. Makes use of the
    `appname <platformdirs.api.PlatformDirsABC.appname>` and
    `version <platformdirs.api.PlatformDirsABC.version>`.
    Ústr©Úreturnc                 C  s   |   tƒ d¡S )zd:return: data directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/files/<AppName>``Úfiles©Ú_append_app_name_and_versionÚ_android_folder©Úself© r   ú]/home/httpd/docs/test/DocsMgr/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¡S )z
        :return: config directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/shared_prefs/<AppName>``
        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¡S )zj:return: cache directory tied to the user, e.g. e.g. ``/data/user/<userid>/<packagename>/cache/<AppName>``Úcacher   r   r   r   r   Úuser_cache_dir(   s    zAndroid.user_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_dir-   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_dir2   s    zAndroid.user_log_dirc                 C  s   t ƒ S )zf
        :return: documents directory tied to the user e.g. ``/storage/emulated/0/Documents``
        )Ú_android_documents_folderr   r   r   r   Úuser_documents_dir=   s    zAndroid.user_documents_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_dirD   s    zAndroid.user_runtime_dirN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   r   r   r   r   r!   r#   r%   r   r   r   r   r      s&   
r   )Úmaxsizer   r   c                  C  sz   z(ddl m}  | dƒ}| ¡  ¡  ¡ }W nL tyt   t d¡}tj	D ] }| 
|¡rF| d¡d } qpqFtdƒ‚Y n0 |S )z':return: base folder for the Android OSr   ©Ú	autoclassúandroid.content.Contextz /data/(data|user/\d+)/(.+)/filesz/filesz&Cannot find path to android app folder)Újniusr-   ZgetFilesDirZgetParentFileÚgetAbsolutePathÚ	ExceptionÚreÚcompileÚsysr   ÚmatchÚsplitÚOSError)r-   ÚContextÚresultÚpatternr   r   r   r   r   P   s    


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,   r.   zandroid.os.Environmentz/storage/emulated/0/Documents)r/   r-   ZgetExternalFilesDirZDIRECTORY_DOCUMENTSr0   r1   )r-   r8   ÚEnvironmentÚdocuments_dirr   r   r   r"   e   s    
r"   )Ú
__future__r   r   r2   r4   Ú	functoolsr   Úapir   r   r   r"   Ú__all__r   r   r   r   Ú<module>   s   Eÿ