Functions
src.utils.files.validate_data_type(path: Path) -> None
Checks if a data file matches a supported data file type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | Path | Path to the data file. | required |
Raises:
Type | Description |
---|---|
ValueError | If data file type not supported. |
Source code in src\utils\files.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
|
src.utils.files.validate_data_file(path: Path) -> None
Checks if a data file exists and is a valid data file type. Raises an exception if validation fails.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | Path | Path to the data file. | required |
Raises:
Type | Description |
---|---|
FileNotFoundError | If data file does not exist. |
ValueError | If data file type not supported. |
Source code in src\utils\files.py
107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
|
src.utils.files.load_data_file(path: Path, config: Optional[dict] = None) -> Union[list, dict, tuple, set]
Load data object from a data file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | Path | Path to the data file to be loaded. | required |
config | dict | None | Dict data to modify DataFileType configuration for this data load procedure. | None |
Returns:
Type | Description |
---|---|
list | dict | tuple | set | Data object such as dict, list, tuple, set, etc. |
Raises:
Type | Description |
---|---|
FileNotFoundError | If data file does not exist. |
ValueError | If data file type not supported. |
OSError | If dumping to data file fails. |
Source code in src\utils\files.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
src.utils.files.dump_data_file(obj: Union[list, dict, tuple, set], path: Path, config: Optional[dict] = None) -> None
Dump data object to a data file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
obj | list | dict | tuple | set | Iterable or dict object to save to data file. | required |
path | Path | Path to the data file to be dumped. | required |
config | dict | None | Dict data to modify DataFileType configuration for this data dump procedure. | None |
Raises:
Type | Description |
---|---|
FileNotFoundError | If data file does not exist. |
ValueError | If data file type not supported. |
OSError | If dumping to data file fails. |
Source code in src\utils\files.py
156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 |
|
src.utils.files.verify_config_fields(ini_file: Path, data_file: Path) -> None
Validate that all settings fields present in a given json data are present in config file. If any are missing, add them and return.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ini_file | Path | Config file to verify contains the proper fields. | required |
data_file | Path | Data file containing config fields to check for, JSON or TOML. | required |
Source code in src\utils\files.py
193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
src.utils.files.parse_kivy_config_json(raw: list[dict]) -> list[dict]
Parse config JSON data for use with Kivy settings panel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw | list[dict] | Raw loaded JSON data. | required |
Returns:
Type | Description |
---|---|
list[dict] | Properly parsed data safe for use with Kivy. |
Source code in src\utils\files.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 |
|
src.utils.files.parse_kivy_config_toml(raw: dict) -> list[dict]
Parse config TOML data for use with Kivy settings panel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
raw | dict | Raw loaded TOML data. | required |
Returns:
Type | Description |
---|---|
list[dict] | Properly parsed data safe for use with Kivy. |
Source code in src\utils\files.py
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 |
|
src.utils.files.get_kivy_config_from_schema(config: Path) -> str
Return valid JSON data for use with Kivy settings panel.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
config | Path | Path to config schema file, JSON or TOML. | required |
Returns:
Type | Description |
---|---|
str | Json string dump of validated data. |
Source code in src\utils\files.py
312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 |
|
src.utils.files.copy_config_or_verify(path_from: Path, path_to: Path, data_file: Path) -> None
Copy one config to another, or verify it if it exists.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path_from | Path | Path to the file to be copied. | required |
path_to | Path | Path to the file to create, if it doesn't exist. | required |
data_file | Path | Data schema file to use for validating an existing INI file. | required |
Source code in src\utils\files.py
330 331 332 333 334 335 336 337 338 339 340 |
|
src.utils.files.remove_config_file(ini_file: str) -> bool
Check if config file exists, then remove it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ini_file | str | Path to an ini file. | required |
Returns:
Type | Description |
---|---|
bool | True if removed, False if not. |
Source code in src\utils\files.py
343 344 345 346 347 348 349 350 351 352 353 354 355 356 |
|
src.utils.files.get_config_object(path: Union[str, os.PathLike, list[Union[str, os.PathLike]]]) -> ConfigParser
Returns a ConfigParser object using a valid ini path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | str | PathLike | list[str | PathLike] | Path to ini config file. | required |
Returns:
Type | Description |
---|---|
ConfigParser | ConfigParser object. |
Raises:
Type | Description |
---|---|
ValueError | If valid ini file wasn't received. |
Source code in src\utils\files.py
359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 |
|
src.utils.files.get_app_version(path: Path) -> str
Returns the version string stored in the root project file.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | Path | Path to the root project file. | required |
Returns:
Type | Description |
---|---|
str | Current version string. |
Source code in src\utils\files.py
382 383 384 385 386 387 388 389 390 391 392 |
|
src.utils.files.check_valid_file(path: Union[str, os.PathLike], ext: Optional[str] = None) -> bool
Checks if a file path provided exists, optionally validate an extension type. @param path: Path to the file to verify. @param ext: Extension to check, if provided. @return: True if file is valid, otherwise False.
Source code in src\utils\files.py
400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 |
|
src.utils.files.ensure_path_exists(path: Union[str, os.PathLike]) -> None
Ensure that directories in path exists. @param path: Folder path to check and create if necessary.
Source code in src\utils\files.py
418 419 420 421 422 423 |
|
src.utils.files.get_unique_filename(path: Path) -> Path
If a filepath exists, number the file according to the lowest number that doesn't exist. @param path: Path to the file.
Source code in src\utils\files.py
426 427 428 429 430 431 432 433 434 435 436 |
|
src.utils.files.get_subdirs(path: Path) -> Iterator[Path]
Yields each subdirectory of a given folder.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path | Path | Path to the folder to iterate over. | required |
Yields:
Type | Description |
---|---|
Path | A subdirectory of the given folder. |
Source code in src\utils\files.py
439 440 441 442 443 444 445 446 447 448 449 450 |
|
src.utils.files.get_file_size_mb(file_path: Union[str, os.PathLike], decimal: int = 1) -> float
Get a file's size in megabytes rounded. @param file_path: Path to the file. @param decimal: Number of decimal places to allow when rounding. @return: Float representing the filesize in megabytes rounded.
Source code in src\utils\files.py
458 459 460 461 462 463 464 465 |
|