]>
crepu.dev Git - config.git/blob - djavu-asus/elpy/rpc-venv/lib/python3.11/site-packages/platformdirs/api.py
2 from __future__
import annotations
5 from abc
import ABC
, abstractmethod
6 from pathlib
import Path
7 from typing
import TYPE_CHECKING
12 if sys
.version_info
>= (3, 8): # pragma: no cover (py38+)
13 from typing
import Literal
14 else: # pragma: no cover (py38+)
15 from typing_extensions
import Literal
18 class PlatformDirsABC(ABC
):
19 """Abstract base class for platform directories."""
21 def __init__( # noqa: PLR0913
23 appname
: str |
None = None,
24 appauthor
: str |
None | Literal
[False] = None,
25 version
: str |
None = None,
26 roaming
: bool = False, # noqa: FBT001, FBT002
27 multipath
: bool = False, # noqa: FBT001, FBT002
28 opinion
: bool = True, # noqa: FBT001, FBT002
29 ensure_exists
: bool = False, # noqa: FBT001, FBT002
32 Create a new platform directory.
34 :param appname: See `appname`.
35 :param appauthor: See `appauthor`.
36 :param version: See `version`.
37 :param roaming: See `roaming`.
38 :param multipath: See `multipath`.
39 :param opinion: See `opinion`.
40 :param ensure_exists: See `ensure_exists`.
42 self
.appname
= appname
#: The name of application.
43 self
.appauthor
= appauthor
45 The name of the app author or distributing body for this application. Typically, it is the owning company name.
46 Defaults to `appname`. You may pass ``False`` to disable it.
48 self
.version
= version
50 An optional version path element to append to the path. You might want to use this if you want multiple versions
51 of your app to be able to run independently. If used, this would typically be ``<major>.<minor>``.
53 self
.roaming
= roaming
55 Whether to use the roaming appdata directory on Windows. That means that for users on a Windows network setup
56 for roaming profiles, this user data will be synced on login (see
57 `here <http://technet.microsoft.com/en-us/library/cc766489(WS.10).aspx>`_).
59 self
.multipath
= multipath
61 An optional parameter which indicates that the entire list of data dirs should be returned.
62 By default, the first item would only be returned.
64 self
.opinion
= opinion
#: A flag to indicating to use opinionated values.
65 self
.ensure_exists
= ensure_exists
67 Optionally create the directory (and any missing parents) upon access if it does not exist.
68 By default, no directories are created.
71 def _append_app_name_and_version(self
, *base
: str) -> str:
72 params
= list(base
[1:])
74 params
.append(self
.appname
)
76 params
.append(self
.version
)
77 path
= os
.path
.join(base
[0], *params
) # noqa: PTH118
78 self
._optionally
_create
_directory
(path
)
81 def _optionally_create_directory(self
, path
: str) -> None:
82 if self
.ensure_exists
:
83 Path(path
).mkdir(parents
=True, exist_ok
=True)
87 def user_data_dir(self
) -> str:
88 """:return: data directory tied to the user"""
92 def site_data_dir(self
) -> str:
93 """:return: data directory shared by users"""
97 def user_config_dir(self
) -> str:
98 """:return: config directory tied to the user"""
102 def site_config_dir(self
) -> str:
103 """:return: config directory shared by the users"""
107 def user_cache_dir(self
) -> str:
108 """:return: cache directory tied to the user"""
112 def site_cache_dir(self
) -> str:
113 """:return: cache directory shared by users"""
117 def user_state_dir(self
) -> str:
118 """:return: state directory tied to the user"""
122 def user_log_dir(self
) -> str:
123 """:return: log directory tied to the user"""
127 def user_documents_dir(self
) -> str:
128 """:return: documents directory tied to the user"""
132 def user_downloads_dir(self
) -> str:
133 """:return: downloads directory tied to the user"""
137 def user_pictures_dir(self
) -> str:
138 """:return: pictures directory tied to the user"""
142 def user_videos_dir(self
) -> str:
143 """:return: videos directory tied to the user"""
147 def user_music_dir(self
) -> str:
148 """:return: music directory tied to the user"""
152 def user_desktop_dir(self
) -> str:
153 """:return: desktop directory tied to the user"""
157 def user_runtime_dir(self
) -> str:
158 """:return: runtime directory tied to the user"""
162 def site_runtime_dir(self
) -> str:
163 """:return: runtime directory shared by users"""
166 def user_data_path(self
) -> Path
:
167 """:return: data path tied to the user"""
168 return Path(self
.user_data_dir
)
171 def site_data_path(self
) -> Path
:
172 """:return: data path shared by users"""
173 return Path(self
.site_data_dir
)
176 def user_config_path(self
) -> Path
:
177 """:return: config path tied to the user"""
178 return Path(self
.user_config_dir
)
181 def site_config_path(self
) -> Path
:
182 """:return: config path shared by the users"""
183 return Path(self
.site_config_dir
)
186 def user_cache_path(self
) -> Path
:
187 """:return: cache path tied to the user"""
188 return Path(self
.user_cache_dir
)
191 def site_cache_path(self
) -> Path
:
192 """:return: cache path shared by users"""
193 return Path(self
.site_cache_dir
)
196 def user_state_path(self
) -> Path
:
197 """:return: state path tied to the user"""
198 return Path(self
.user_state_dir
)
201 def user_log_path(self
) -> Path
:
202 """:return: log path tied to the user"""
203 return Path(self
.user_log_dir
)
206 def user_documents_path(self
) -> Path
:
207 """:return: documents path tied to the user"""
208 return Path(self
.user_documents_dir
)
211 def user_downloads_path(self
) -> Path
:
212 """:return: downloads path tied to the user"""
213 return Path(self
.user_downloads_dir
)
216 def user_pictures_path(self
) -> Path
:
217 """:return: pictures path tied to the user"""
218 return Path(self
.user_pictures_dir
)
221 def user_videos_path(self
) -> Path
:
222 """:return: videos path tied to the user"""
223 return Path(self
.user_videos_dir
)
226 def user_music_path(self
) -> Path
:
227 """:return: music path tied to the user"""
228 return Path(self
.user_music_dir
)
231 def user_desktop_path(self
) -> Path
:
232 """:return: desktop path tied to the user"""
233 return Path(self
.user_desktop_dir
)
236 def user_runtime_path(self
) -> Path
:
237 """:return: runtime path tied to the user"""
238 return Path(self
.user_runtime_dir
)
241 def site_runtime_path(self
) -> Path
:
242 """:return: runtime path shared by users"""
243 return Path(self
.site_runtime_dir
)