
    )h5#                    0   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	e      Z ed
      dd       Z ed
      dd       Z ed
      dd       Z ed
      dd       Z ed
      dd       Z ed
      dd       Zd	gZy)zAndroid.    )annotationsN)	lru_cache)TYPE_CHECKINGcast   )PlatformDirsABCc                  0   e Zd ZdZedd       Zedd       Zedd       Zedd       Zedd       Z	edd       Z
edd       Zedd	       Zedd
       Zedd       Zedd       Zedd       Zedd       Zedd       Zedd       Zedd       Zy)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>`.

    c                J    | j                  t        dt                     d      S )zd:return: data directory tied to the user, e.g. ``/data/user/<userid>/<packagename>/files/<AppName>``strfiles_append_app_name_and_versionr   _android_folderselfs    S/var/www/html/venv/lib/python3.12/site-packages/pip/_vendor/platformdirs/android.pyuser_data_dirzAndroid.user_data_dir   "     00e_=N1OQXYY    c                    | j                   S )z@:return: data directory shared by users, same as `user_data_dir`r   r   s    r   site_data_dirzAndroid.site_data_dir        !!!r   c                J    | j                  t        dt                     d      S )z
        :return: config directory tied to the user, e.g.         ``/data/user/<userid>/<packagename>/shared_prefs/<AppName>``
        r   shared_prefsr   r   s    r   user_config_dirzAndroid.user_config_dir!   s"     00e_=N1OQ_``r   c                    | j                   S )zH:return: config directory shared by the users, same as `user_config_dir`)r   r   s    r   site_config_dirzAndroid.site_config_dir)   s     ###r   c                J    | j                  t        dt                     d      S )ze:return: cache directory tied to the user, e.g.,``/data/user/<userid>/<packagename>/cache/<AppName>``r   cacher   r   s    r   user_cache_dirzAndroid.user_cache_dir.   r   r   c                    | j                   S )zB:return: cache directory shared by users, same as `user_cache_dir`)r"   r   s    r   site_cache_dirzAndroid.site_cache_dir3   s     """r   c                    | j                   S )zB:return: state directory tied to the user, same as `user_data_dir`r   r   s    r   user_state_dirzAndroid.user_state_dir8   r   r   c                v    | j                   }| j                  r t        j                  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,   s     r   user_log_dirzAndroid.user_log_dir=   /     ""<<77<<e,Dr   c                    t               S )zT:return: documents directory tied to the user e.g. ``/storage/emulated/0/Documents``)_android_documents_folderr   s    r   user_documents_dirzAndroid.user_documents_dirH        )**r   c                    t               S )zT:return: downloads directory tied to the user e.g. ``/storage/emulated/0/Downloads``)_android_downloads_folderr   s    r   user_downloads_dirzAndroid.user_downloads_dirM   r4   r   c                    t               S )zR:return: pictures directory tied to the user e.g. ``/storage/emulated/0/Pictures``)_android_pictures_folderr   s    r   user_pictures_dirzAndroid.user_pictures_dirR   s     ())r   c                    t               S )zS:return: videos directory tied to the user e.g. ``/storage/emulated/0/DCIM/Camera``)_android_videos_folderr   s    r   user_videos_dirzAndroid.user_videos_dirW   s     &''r   c                    t               S )zL:return: music directory tied to the user e.g. ``/storage/emulated/0/Music``)_android_music_folderr   s    r   user_music_dirzAndroid.user_music_dir\   s     %&&r   c                     y)zP:return: desktop directory tied to the user e.g. ``/storage/emulated/0/Desktop``z/storage/emulated/0/Desktop r   s    r   user_desktop_dirzAndroid.user_desktop_dira   s     -r   c                v    | j                   }| j                  r t        j                  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.   s     r   user_runtime_dirzAndroid.user_runtime_dirf   r0   r   c                    | j                   S )zF:return: runtime directory shared by users, same as `user_runtime_dir`)rF   r   s    r   site_runtime_dirzAndroid.site_runtime_dirq   s     $$$r   Nreturnr   )__name__
__module____qualname____doc__propertyr   r   r   r   r"   r$   r&   r/   r3   r7   r:   r=   r@   rC   rF   rH   rB   r   r   r
   r
      sM    Z Z " " a a $ $ Z Z # # " "   + + + + * * ( ( ' ' - -   % %r   r
   )maxsizec                    d} t         sM	 ddlm} t        d|j	                               }|j                         j                         j                         } | ;	 ddl	m
}  |d      }|j                         j                         j                         } | St        j                  d      }t        j                  D ])  }|j                  |      s|j!                  d      d   }  n d} | Tt        j                  d      }t        j                  D ]*  }|j                  |      s|j!                  d      d   }  | S  d} | S # t        $ r d} Y w xY w# t        $ r d} Y w xY w)	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   androidrR   r   getApplicationContextgetFilesDirgetParentFilegetAbsolutePath	ExceptionjniusrU   recompilesysr,   matchsplit)resultrR   contextrU   patternr,   s         r   r   r   w   sf    F 	)4i6U6U6WXG((*88:JJLF ~	 ( 9:G((*88:JJLF ~ **@AHH 	D}}T"H-a0	
 F~ **WXHH 	D}}T"H-a0 M	
 FMA  	F	  	F	s$   AE  :E  EEEEc                     	 ddl m}   | d      } | d      }|j                  |j                        j	                         }|S # t
        $ r d}Y |S w xY w)z,:return: documents folder for the Android OSr   rT   rS   android.os.Environmentz/storage/emulated/0/Documents)r\   rU   getExternalFilesDirDIRECTORY_DOCUMENTSrZ   r[   )rU   rc   environmentdocuments_dirs       r   r2   r2      c    8#56 89$889X9XYiik   878   ?A AAc                     	 ddl m}   | d      } | d      }|j                  |j                        j	                         }|S # t
        $ r d}Y |S w xY w)z,:return: downloads folder for the Android OSr   rT   rS   rf   z/storage/emulated/0/Downloads)r\   rU   rg   DIRECTORY_DOWNLOADSrZ   r[   )rU   rc   ri   downloads_dirs       r   r6   r6      rk   rl   c                     	 ddl m}   | d      } | d      }|j                  |j                        j	                         }|S # t
        $ r d}Y |S w xY w)z+:return: pictures folder for the Android OSr   rT   rS   rf   z/storage/emulated/0/Pictures)r\   rU   rg   DIRECTORY_PICTURESrZ   r[   )rU   rc   ri   pictures_dirs       r   r9   r9      sc    6#56 89#778V8VWggi   656rl   c                     	 ddl m}   | d      } | d      }|j                  |j                        j	                         }|S # t
        $ r d}Y |S w xY w)z):return: videos folder for the Android OSr   rT   rS   rf   z/storage/emulated/0/DCIM/Camera)r\   rU   rg   DIRECTORY_DCIMrZ   r[   )rU   rc   ri   
videos_dirs       r   r<   r<      sc    7#56 89!55k6P6PQaac
   76
7rl   c                     	 ddl m}   | d      } | d      }|j                  |j                        j	                         }|S # t
        $ r d}Y |S w xY w)z(:return: music folder for the Android OSr   rT   rS   rf   z/storage/emulated/0/Music)r\   rU   rg   DIRECTORY_MUSICrZ   r[   )rU   rc   ri   	music_dirs       r   r?   r?      sc    0#56 89 44[5P5PQaac	   0/	0rl   )rJ   z
str | NonerI   )rN   
__future__r   r+   r]   r_   	functoolsr   typingr   r   apir   r
   r   r2   r6   r9   r<   r?   __all__rB   r   r   <module>r~      s     " 	 	 
  &  f%o f%R 1, ,^ 1  1  1  1  1   r   