o
    wi_)                     @  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Zedd
dddZedd
dddZedd
dddZedd
dddZedd
dddZd	gZdS )zAndroid.    )annotationsN)	lru_cache)TYPE_CHECKINGcast   )PlatformDirsABCc                   @  sD  e Zd ZdZed1ddZed1ddZed1dd	Zed1d
dZed1ddZ	ed1ddZ
ed1ddZed1ddZed1ddZed1ddZed1ddZed1ddZed1ddZed1ddZed1d d!Zed1d"d#Zed1d$d%Zed1d&d'Zed1d(d)Zed1d*d+Zed1d,d-Zed1d.d/Zd0S )2Androida  Platform directories for Android.

    Follows the guidance `from here <https://android.stackexchange.com/a/216132>`_. Directories are typically located
    under the app's private storage (``/data/user/<userid>/<packagename>/``).

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

    returnstrc                 C     |  tdt dS )ze:returns: data directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/files/<AppName>``r
   files_append_app_name_and_versionr   _android_folderself r   Q/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/platformdirs/android.pyuser_data_dir      zAndroid.user_data_dirc                 C     | j S )zA:returns: data directory shared by users, same as `user_data_dir`r   r   r   r   r   site_data_dir      zAndroid.site_data_dirc                 C  r   )zn:returns: config directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/shared_prefs/<AppName>``r
   shared_prefsr   r   r   r   r   user_config_dir$   r   zAndroid.user_config_dirc                 C  r   )zE:returns: config directory shared by users, same as `user_config_dir`)r   r   r   r   r   site_config_dir)   r   zAndroid.site_config_dirc                 C  r   )zf:returns: cache directory tied to the user, e.g.,``/data/user/<userid>/<packagename>/cache/<AppName>``r
   cacher   r   r   r   r   user_cache_dir.   r   zAndroid.user_cache_dirc                 C  r   )zC:returns: cache directory shared by users, same as `user_cache_dir`)r   r   r   r   r   site_cache_dir3   r   zAndroid.site_cache_dirc                 C  r   )zC:returns: state directory tied to the user, same as `user_data_dir`r   r   r   r   r   user_state_dir8   r   zAndroid.user_state_dirc                 C  r   )zC:returns: state directory shared by users, same as `user_state_dir`)r    r   r   r   r   site_state_dir=   r   zAndroid.site_state_dirc                 C  (   | j }| jrtj|d}| | |S )z:returns: 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_optionally_create_directoryr   r'   r   r   r   user_log_dirB   
   
zAndroid.user_log_dirc                 C  r   )z?:returns: log directory shared by users, same as `user_log_dir`)r+   r   r   r   r   site_log_dirK   r   zAndroid.site_log_dirc                 C     t  S )zU:returns: documents directory tied to the user e.g. ``/storage/emulated/0/Documents``)_android_documents_folderr   r   r   r   user_documents_dirP   r   zAndroid.user_documents_dirc                 C  r.   )zU:returns: downloads directory tied to the user e.g. ``/storage/emulated/0/Downloads``)_android_downloads_folderr   r   r   r   user_downloads_dirU   r   zAndroid.user_downloads_dirc                 C  r.   )zS:returns: pictures directory tied to the user e.g. ``/storage/emulated/0/Pictures``)_android_pictures_folderr   r   r   r   user_pictures_dirZ   r   zAndroid.user_pictures_dirc                 C  r.   )zT:returns: videos directory tied to the user e.g. ``/storage/emulated/0/DCIM/Camera``)_android_videos_folderr   r   r   r   user_videos_dir_   r   zAndroid.user_videos_dirc                 C  r.   )zM:returns: music directory tied to the user e.g. ``/storage/emulated/0/Music``)_android_music_folderr   r   r   r   user_music_dird   r   zAndroid.user_music_dirc                 C  s   dS )zQ:returns: desktop directory tied to the user e.g. ``/storage/emulated/0/Desktop``z/storage/emulated/0/Desktopr   r   r   r   r   user_desktop_diri   s   zAndroid.user_desktop_dirc                 C  s   t jtdt ddS )z^:returns: bin directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/files/bin``r
   r   bin)r&   r'   r(   r   r   r   r   r   r   user_bin_dirn   s   zAndroid.user_bin_dirc                 C  r   )z?:returns: bin directory shared by users, same as `user_bin_dir`)r;   r   r   r   r   site_bin_dirs   r   zAndroid.site_bin_dirc                 C  r   )zJ:returns: applications directory tied to the user, same as `user_data_dir`r   r   r   r   r   user_applications_dirx   r   zAndroid.user_applications_dirc                 C  r   )zQ:returns: applications directory shared by users, same as `user_applications_dir`)r=   r   r   r   r   site_applications_dir}   r   zAndroid.site_applications_dirc                 C  r"   )z:returns: 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_dir   r,   zAndroid.user_runtime_dirc                 C  r   )zG:returns: runtime directory shared by users, same as `user_runtime_dir`)r@   r   r   r   r   site_runtime_dir   r   zAndroid.site_runtime_dirNr	   r
   )__name__
__module____qualname____doc__propertyr   r   r   r   r   r   r    r!   r+   r-   r0   r2   r4   r6   r8   r9   r;   r<   r=   r>   r@   rA   r   r   r   r   r      s\    r   )maxsizer	   
str | Nonec                  C  s  d} t s'zddlm} td| }|   } W n ty&   d} Y nw | du rKzddl	m
} |d}|   } W n tyJ   d} Y nw | du rjtd}tjD ]}||rg|dd }  nqWd} | du rtd}tjD ]}||r|dd }  | S qvd} | S )	zF:returns: 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   androidrJ   r   getApplicationContextgetFilesDirgetParentFilegetAbsolutePath	ExceptionjniusrM   recompilesysr'   matchsplit)resultrJ   contextrM   patternr'   r   r   r   r      sF   





r   r
   c                  C  L   zddl m}  | d}| d}||j }W |S  ty%   d}Y |S w )z-:returns: documents folder for the Android OSr   rL   rK   android.os.Environmentz/storage/emulated/0/Documents)rT   rM   getExternalFilesDirDIRECTORY_DOCUMENTSrR   rS   )rM   r[   environmentdocuments_dirr   r   r   r/         r/   c                  C  r]   )z-:returns: downloads folder for the Android OSr   rL   rK   r^   z/storage/emulated/0/Downloads)rT   rM   r_   DIRECTORY_DOWNLOADSrR   rS   )rM   r[   ra   downloads_dirr   r   r   r1      rc   r1   c                  C  r]   )z,:returns: pictures folder for the Android OSr   rL   rK   r^   z/storage/emulated/0/Pictures)rT   rM   r_   DIRECTORY_PICTURESrR   rS   )rM   r[   ra   pictures_dirr   r   r   r3      rc   r3   c                  C  r]   )z*:returns: videos folder for the Android OSr   rL   rK   r^   z/storage/emulated/0/DCIM/Camera)rT   rM   r_   DIRECTORY_DCIMrR   rS   )rM   r[   ra   
videos_dirr   r   r   r5      rc   r5   c                  C  r]   )z):returns: music folder for the Android OSr   rL   rK   r^   z/storage/emulated/0/Music)rT   rM   r_   DIRECTORY_MUSICrR   rS   )rM   r[   ra   	music_dirr   r   r   r7     rc   r7   )r	   rI   rB   )rF   
__future__r   r&   rU   rW   	functoolsr   typingr   r   apir   r   r   r/   r1   r3   r5   r7   __all__r   r   r   r   <module>   s0     /