U e_)@sdZddlmZddlZddlZddlmZddlmZddl m Z ddl m Z ej d krjd d d d Zn ddlmZGddde ZddddddZdddddZdgZdS)zUnix.) annotationsN) ConfigParser)Path)Iterator)PlatformDirsABCwin32intreturncCsd}t|dS)Nzshould only be used on Unix) RuntimeError)msgr?/opt/hc_python/lib/python3.8/site-packages/platformdirs/unix.pygetuidsr)rc@seZdZdZeddddZeddddZeddd d Zeddd d Zeddd dZ eddddZ eddddZ eddddZ eddddZ eddddZeddddZeddddZeddddZedddd Zeddd!d"Zeddd#d$Zeddd%d&Zeddd'd(Zed)dd*d+Zed)dd,d-Zed)dd.d/Zdd)d0d1d2Zd3dd4d5Zd3dd6d7Zd8S)9Unixa 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 `, `ensure_exists `. strr cCs,tjdd}|s"tjd}||S)z :return: data directory tied to the user, e.g. ``~/.local/share/$appname/$version`` or ``$XDG_DATA_HOME/$appname/$version`` XDG_DATA_HOMEz~/.local/shareosenvirongetstrippath expanduser_append_app_name_and_versionselfrrrr user_data_dir$s zUnix.user_data_dirz list[str]cs>tjdd}|s$dtjd}fdd|tjDS)N XDG_DATA_DIRSrz/usr/local/sharez /usr/sharecsg|]}|qSrr.0prrr 4sz(Unix._site_data_dirs..)rrrrpathsepsplitrrr%r_site_data_dirs/szUnix._site_data_dirscCs |j}|js|dStj|S)aZ :return: data directories shared by users (if `multipath ` is enabled and ``XDG_DATA_DIRS`` 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`` r)r) multipathrr'joinrdirsrrr site_data_dir6szUnix.site_data_dircCs,tjdd}|s"tjd}||S)z :return: config directory tied to the user, e.g. ``~/.config/$appname/$version`` or ``$XDG_CONFIG_HOME/$appname/$version`` XDG_CONFIG_HOMErz ~/.configrrrrruser_config_dirCs zUnix.user_config_dircs4tjdd}|sd}fdd|tjDS)NXDG_CONFIG_DIRSrz/etc/xdgcsg|]}|qSrr!r"r%rrr&Ssz*Unix._site_config_dirs..)rrrrr(r'rrr%r_site_config_dirsNszUnix._site_config_dirscCs |j}|js|dStj|S)a2 :return: config directories shared by users (if `multipath ` is enabled and ``XDG_CONFIG_DIRS`` 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`` r)r2r*rr'r+r,rrrsite_config_dirUszUnix.site_config_dircCs,tjdd}|s"tjd}||S)z :return: cache directory tied to the user, e.g. ``~/.cache/$appname/$version`` or ``~/$XDG_CACHE_HOME/$appname/$version`` XDG_CACHE_HOMErz~/.cacherrrrruser_cache_dirbs zUnix.user_cache_dircCs |dS)zO:return: cache directory shared by users, e.g. ``/var/cache/$appname/$version``z /var/cacher!r%rrrsite_cache_dirmszUnix.site_cache_dircCs,tjdd}|s"tjd}||S)z :return: state directory tied to the user, e.g. ``~/.local/state/$appname/$version`` or ``$XDG_STATE_HOME/$appname/$version`` XDG_STATE_HOMErz~/.local/staterrrrruser_state_dirrs zUnix.user_state_dircCs(|j}|jr$tj|d}|||S)zg:return: log directory tied to the user, same as `user_state_dir` if not opinionated else ``log`` in itlog)r8opinionrrr+_optionally_create_directoryrrrr user_log_dir}s  zUnix.user_log_dircCs tddS)zC:return: documents directory tied to the user, e.g. ``~/Documents``XDG_DOCUMENTS_DIRz ~/Documents_get_user_media_dirr%rrruser_documents_dirszUnix.user_documents_dircCs tddS)zC:return: downloads directory tied to the user, e.g. ``~/Downloads``XDG_DOWNLOAD_DIRz ~/Downloadsr>r%rrruser_downloads_dirszUnix.user_downloads_dircCs tddS)zA:return: pictures directory tied to the user, e.g. ``~/Pictures``XDG_PICTURES_DIRz ~/Picturesr>r%rrruser_pictures_dirszUnix.user_pictures_dircCs tddS)z=:return: videos directory tied to the user, e.g. ``~/Videos``XDG_VIDEOS_DIRz~/Videosr>r%rrruser_videos_dirszUnix.user_videos_dircCs tddS)z;:return: music directory tied to the user, e.g. ``~/Music`` XDG_MUSIC_DIRz~/Musicr>r%rrruser_music_dirszUnix.user_music_dircCs tddS)z?:return: desktop directory tied to the user, e.g. ``~/Desktop``ZXDG_DESKTOP_DIRz ~/Desktopr>r%rrruser_desktop_dirszUnix.user_desktop_dircCs^tjdd}|sTtjdrHdt}t| sTdt}n dt}| |S)az :return: runtime directory tied to the user, e.g. ``/run/user/$(id -u)/$appname/$version`` or ``$XDG_RUNTIME_DIR/$appname/$version``. For FreeBSD/OpenBSD/NetBSD, it would return ``/var/run/user/$(id -u)/$appname/$version`` if exists, otherwise ``/tmp/runtime-$(id -u)/$appname/$version``, if``$XDG_RUNTIME_DIR`` is not set. XDG_RUNTIME_DIRrfreebsdopenbsdnetbsdz/var/run/user/z /tmp/runtime-z /run/user/) rrrrsysplatform startswithrrexistsrrrrruser_runtime_dirs     zUnix.user_runtime_dircCs6tjdd}|s,tjdr(d}nd}||S)am :return: runtime directory shared by users, e.g. ``/run/$appname/$version`` or ``$XDG_RUNTIME_DIR/$appname/$version``. Note that this behaves almost exactly like `user_runtime_dir` if ``$XDG_RUNTIME_DIR`` is set, but will fall back to paths associated to the root user instead of a regular logged-in user if it's not set. If you wish to ensure that a logged-in root user path is returned e.g. ``/run/user/0``, use `user_runtime_dir` instead. For FreeBSD/OpenBSD/NetBSD, it would return ``/var/run/$appname/$version`` if ``$XDG_RUNTIME_DIR`` is not set. rJrrKz/var/runz/run)rrrrrOrPrQrrrrrsite_runtime_dirs  zUnix.site_runtime_dirrcCs ||jS)zd:return: data path shared by users. Only return first item, even if ``multipath`` is set to ``True``) _first_item_as_path_if_multipathr.r%rrrsite_data_pathszUnix.site_data_pathcCs ||jS)zj:return: config path shared by the users. Only return first item, even if ``multipath`` is set to ``True``)rUr3r%rrrsite_config_pathszUnix.site_config_pathcCs ||jS)ze:return: cache path shared by users. Only return first item, even if ``multipath`` is set to ``True``)rUr6r%rrrsite_cache_pathszUnix.site_cache_path) directoryr cCs|jr|tjd}t|S)Nr)r*r(rr'r)rrYrrrrUsz%Unix._first_item_as_path_if_multipathz Iterator[str]ccs|jV|jEdHdS)z4:yield: all user and site configuration directories.N)r0r2r%rrriter_config_dirsszUnix.iter_config_dirsccs|jV|jEdHdS)z+:yield: all user and site data directories.N)rr)r%rrriter_data_dirsszUnix.iter_data_dirsN)__name__ __module__ __qualname____doc__propertyrr)r.r0r2r3r5r6r8r<r@rBrDrFrHrIrSrTrVrWrXrUrZr[rrrrrs\       rr)env_varfallback_tilde_pathr cCs6t|}|dkr2tj|d}|s2tj|}|S)Nr)_get_user_dirs_folderrrrrrr)rarb media_dirrrrr?s  r?z str | None)keyr c Csttjd}|r|t}|}|d|W5QRX||dkrVdS|d|d}| dt j dSdS)zkReturn directory from user-dirs.dirs config file. See https://freedesktop.org/wiki/Software/xdg-user-dirs/.zuser-dirs.dirsz[top] topN"z$HOME~) rrr0rRropen read_stringreadrreplacerrr)reuser_dirs_config_pathparserstreamrrrrrcs  rc)r_ __future__rrrO configparserrpathlibrtypingrapirrPrrr?rc__all__rrrrs        X