a „oeÿã@s’ddlmZddlZddlZddlmZddlmZddlm Z ej   d¡rZddlm Z nd d œd d „Z Gd d„de ƒZ dddœdd„ZdgZdS)é)Ú annotationsN)Ú ConfigParser)ÚPathé)ÚPlatformDirsABCZlinux)ÚgetuidÚint©ÚreturncCs tdƒ‚dS)Nzshould only be used on Linux)Ú RuntimeError©r r úHC:\Program Files\Certbot\pkgs\pkg_resources\_vendor\platformdirs\unix.pyrsrc@söeZdZdZeddœdd„ƒZeddœdd„ƒZdddœd d „Zeddœd d „ƒZeddœd d„ƒZ eddœdd„ƒZ eddœdd„ƒZ eddœdd„ƒZ eddœdd„ƒZ eddœdd„ƒZeddœdd„ƒZeddœdd„ƒZdddœdd „Zd!S)"ÚUnixaD On Unix/Linux, we follow the `XDG Basedir Spec `_. The spec allows overriding directories with environment variables. The examples show are the default values, alongside the name of the environment variable that overrides them. Makes use of the `appname `, `version `, `multipath `, `opinion `. Ústrr cCs,tj dd¡}| ¡s"tj d¡}| |¡S)z– :return: data directory tied to the user, e.g. ``~/.local/share/$appname/$version`` or ``$XDG_DATA_HOME/$appname/$version`` Z XDG_DATA_HOMEÚz~/.local/share©ÚosÚenvironÚgetÚstripÚpathÚ expanduserÚ_append_app_name_and_version©Úselfrr r r Ú user_data_dirs zUnix.user_data_dircCs.tj dd¡}| ¡s$dtj›d�}| |¡S)aY :return: data directories shared by users (if `multipath ` is enabled and ``XDG_DATA_DIR`` is set and a multi path the response is also a multi path separated by the OS path separator), e.g. ``/usr/local/share/$appname/$version`` or ``/usr/share/$appname/$version`` Z XDG_DATA_DIRSrz/usr/local/sharez /usr/share)rrrrÚpathsepÚ_with_multi_pathrr r r Ú site_data_dir)szUnix.site_data_dir)rr cs<| tj¡}ˆjs|dd…}‡fdd„|Dƒ}tj |¡S)Nrrcsg|]}ˆ tj |¡¡‘qSr )rrrr)Ú.0Úp©rr r Ú :óz)Unix._with_multi_path..)ÚsplitrrÚ multipathÚjoin)rrÚ path_listr r!r r6s   zUnix._with_multi_pathcCs,tj dd¡}| ¡s"tj d¡}| |¡S)z• :return: config directory tied to the user, e.g. ``~/.config/$appname/$version`` or ``$XDG_CONFIG_HOME/$appname/$version`` ZXDG_CONFIG_HOMErz ~/.configrrr r r Úuser_config_dir=s zUnix.user_config_dircCs$tj dd¡}| ¡sd}| |¡S)a/ :return: config directories shared by users (if `multipath ` is enabled and ``XDG_DATA_DIR`` is set and a multi path the response is also a multi path separated by the OS path separator), e.g. ``/etc/xdg/$appname/$version`` ZXDG_CONFIG_DIRSrz/etc/xdg)rrrrrrr r r Úsite_config_dirHszUnix.site_config_dircCs,tj dd¡}| ¡s"tj d¡}| |¡S)z” :return: cache directory tied to the user, e.g. ``~/.cache/$appname/$version`` or ``~/$XDG_CACHE_HOME/$appname/$version`` ZXDG_CACHE_HOMErz~/.cacherrr r r Úuser_cache_dirUs zUnix.user_cache_dircCs,tj dd¡}| ¡s"tj d¡}| |¡S)z˜ :return: state directory tied to the user, e.g. ``~/.local/state/$appname/$version`` or ``$XDG_STATE_HOME/$appname/$version`` ZXDG_STATE_HOMErz~/.local/staterrr r r Úuser_state_dir`s zUnix.user_state_dircCs|j}|jrtj |d¡}|S)zy :return: log directory tied to the user, same as `user_state_dir` if not opinionated else ``log`` in it Úlog)r+Zopinionrrr&rr r r Ú user_log_dirkszUnix.user_log_dircCs6tdƒ}|dur2tj dd¡ ¡}|s2tj d¡}|S)zU :return: documents directory tied to the user, e.g. ``~/Documents`` ZXDG_DOCUMENTS_DIRNrz ~/Documents)Ú_get_user_dirs_folderrrrrrr)rZ documents_dirr r r Úuser_documents_dirus  zUnix.user_documents_dircCs,tj dd¡}| ¡s"dtƒ›�}| |¡S)zŸ :return: runtime directory tied to the user, e.g. ``/run/user/$(id -u)/$appname/$version`` or ``$XDG_RUNTIME_DIR/$appname/$version`` ZXDG_RUNTIME_DIRrz /run/user/)rrrrrrrr r r Úuser_runtime_dir‚s zUnix.user_runtime_dirrcCs | |j¡S)zd:return: data path shared by users. Only return first item, even if ``multipath`` is set to ``True``)Ú _first_item_as_path_if_multipathrr!r r r Úsite_data_path�szUnix.site_data_pathcCs | |j¡S)zj:return: config path shared by the users. Only return first item, even if ``multipath`` is set to ``True``)r1r)r!r r r Úsite_config_path’szUnix.site_config_path)Ú directoryr cCs|jr| tj¡d}t|ƒS)Nr)r%r$rrr)rr4r r r r1—sz%Unix._first_item_as_path_if_multipathN)Ú__name__Ú __module__Ú __qualname__Ú__doc__Úpropertyrrrr(r)r*r+r-r/r0r2r3r1r r r r rs2          rrz str | None)Úkeyr cCsžtj tƒjd¡}tj |¡rštƒ}t|ƒ�$}| d|  ¡›�¡Wdƒn1sV0Y||dvrpdS|d|  d¡}|  dtj  d¡¡}|SdS)zjReturn directory from user-dirs.dirs config file. See https://freedesktop.org/wiki/Software/xdg-user-dirs/zuser-dirs.dirsz[top] NÚtopú"z$HOMEú~) rrr&rr(ÚexistsrÚopenZ read_stringÚreadrÚreplacer)r:Zuser_dirs_config_pathÚparserÚstreamrr r r r.žs  2 r.)Z __future__rrÚsysZ configparserrÚpathlibrZapirÚplatformÚ startswithrrr.Ú__all__r r r r Ús      ÿ