IO Utilities
async_create_dir(create_dir, warn_mode=WarnEnum.DEBUG)
async
Asynchronous create directory if create_dir doesn't exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
create_dir
|
(str, required)
|
Create directory path. |
required |
warn_mode
|
WarnEnum | str
|
Warning message mode, for example: 'ERROR', 'ALWAYS', 'DEBUG', 'IGNORE'. Defaults to 'DEBUG'. |
DEBUG
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
OSError
|
When warning mode is set to ERROR and directory already exists. |
OSError
|
If failed to create directory. |
Source code in src/potato_util/io/_async.py
async_get_file_checksum(file_path, hash_method=HashAlgoEnum.md5, chunk_size=4096, warn_mode=WarnEnum.DEBUG)
async
Asynchronous get file checksum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
(str, required)
|
Target file path. |
required |
hash_method
|
HashAlgoEnum
|
Hash method. Defaults to |
md5
|
chunk_size
|
int
|
Chunk size. Defaults to 4096. |
4096
|
warn_mode
|
WarnEnum | str
|
Warning message mode, for example: 'ERROR', 'ALWAYS', 'DEBUG', 'IGNORE'. Defaults to 'DEBUG'. |
DEBUG
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
OSError
|
When warning mode is set to ERROR and file doesn't exist. |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: File checksum or None if file doesn't exist. |
Source code in src/potato_util/io/_async.py
async_read_config_file(config_path)
async
Asynchronous read config file (YAML, JSON, TOML, INI).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
(str | Path, required)
|
Config file path. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If config file is not found. |
ValueError
|
If config file format is not supported. |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Config file data as dictionary. |
Source code in src/potato_util/io/_async.py
async_read_ini_file(file_path)
async
Asynchronous read INI config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
(str | Path, required)
|
INI config file path. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If INI config file is not found. |
Exception
|
If failed to read INI config file. |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: INI config file data as dictionary. |
Source code in src/potato_util/io/_async.py
async_read_json_file(file_path)
async
Asynchronous read JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
(str | Path, required)
|
JSON file path. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If JSON file is not found. |
Exception
|
If failed to read JSON file. |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: JSON file data as dictionary. |
Source code in src/potato_util/io/_async.py
async_read_toml_file(file_path)
async
Asynchronous read TOML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
(str | Path, required)
|
TOML file path. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If TOML file is not found. |
Exception
|
If failed to read TOML file. |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: TOML file data as dictionary. |
Source code in src/potato_util/io/_async.py
async_read_yaml_file(file_path)
async
Asynchronous read YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
(str | Path, required)
|
YAML file path. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If YAML file is not found. |
Exception
|
If failed to read YAML file. |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: YAML file data as dictionary. |
Source code in src/potato_util/io/_async.py
async_remove_dir(remove_dir, warn_mode=WarnEnum.DEBUG)
async
Asynchronous remove directory if remove_dir exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
remove_dir
|
(str, required)
|
Remove directory path. |
required |
warn_mode
|
WarnEnum | str
|
Warning message mode, for example: 'ERROR', 'ALWAYS', 'DEBUG', 'IGNORE'. Defaults to 'DEBUG'. |
DEBUG
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
OSError
|
When warning mode is set to ERROR and directory doesn't exist. |
OSError
|
If failed to remove directory. |
Source code in src/potato_util/io/_async.py
async_remove_dirs(remove_dirs, warn_mode=WarnEnum.DEBUG)
async
Asynchronous remove directories if remove_dirs exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
remove_dirs
|
(list[str], required)
|
Remove directories paths as list. |
required |
warn_mode
|
WarnEnum | str
|
Warning message mode, for example: 'ERROR', 'ALWAYS', 'DEBUG', 'IGNORE'. Defaults to 'DEBUG'. |
DEBUG
|
Source code in src/potato_util/io/_async.py
async_remove_file(file_path, warn_mode=WarnEnum.DEBUG)
async
Asynchronous remove file if file_path exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
(str, required)
|
Remove file path. |
required |
warn_mode
|
WarnEnum | str
|
Warning message mode, for example: 'ERROR', 'ALWAYS', 'DEBUG', 'IGNORE'. Defaults to 'DEBUG'. |
DEBUG
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
OSError
|
When warning mode is set to ERROR and file doesn't exist. |
OSError
|
If failed to remove file. |
Source code in src/potato_util/io/_async.py
async_remove_files(file_paths, warn_mode=WarnEnum.DEBUG)
async
Asynchronous remove files if file_paths exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_paths
|
(list[str], required)
|
Remove file paths as list. |
required |
warn_mode
|
WarnEnum | str
|
Warning message mode, for example: 'ERROR', 'ALWAYS', 'DEBUG', 'IGNORE'. Defaults to 'DEBUG'. |
DEBUG
|
Source code in src/potato_util/io/_async.py
create_dir(create_dir, warn_mode=WarnEnum.DEBUG)
Create directory if create_dir doesn't exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
create_dir
|
(str, required)
|
Create directory path. |
required |
warn_mode
|
WarnEnum | str
|
Warning message mode, for example: 'ERROR', 'ALWAYS', 'DEBUG', 'IGNORE'. Defaults to 'DEBUG'. |
DEBUG
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
OSError
|
When warning mode is set to ERROR and directory already exists. |
OSError
|
If failed to create directory. |
Source code in src/potato_util/io/_sync.py
get_file_checksum(file_path, hash_method=HashAlgoEnum.md5, chunk_size=4096, warn_mode=WarnEnum.DEBUG)
Get file checksum.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
(str, required)
|
Target file path. |
required |
hash_method
|
HashAlgoEnum
|
Hash method. Defaults to |
md5
|
chunk_size
|
int
|
Chunk size. Defaults to 4096. |
4096
|
warn_mode
|
WarnEnum | str
|
Warning message mode, for example: 'ERROR', 'ALWAYS', 'DEBUG', 'IGNORE'. Defaults to 'DEBUG'. |
DEBUG
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
ValueError
|
If |
OSError
|
When warning mode is set to ERROR and file doesn't exist. |
Returns:
| Type | Description |
|---|---|
str | None
|
str | None: File checksum or None if file doesn't exist. |
Source code in src/potato_util/io/_sync.py
read_config_file(config_path)
Read config file (YAML, JSON, TOML, INI).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config_path
|
(str | Path, required)
|
Config file path. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If config file is not found. |
ValueError
|
If config file format is not supported. |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: Config file data as dictionary. |
Source code in src/potato_util/io/_sync.py
read_ini_file(file_path)
Read INI config file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
(str | Path, required)
|
INI config file path. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If INI config file is not found. |
Exception
|
If failed to read INI config file. |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: INI config file data as dictionary. |
Source code in src/potato_util/io/_sync.py
read_json_file(file_path)
Read JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
(str | Path, required)
|
JSON file path. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If JSON file is not found. |
Exception
|
If failed to read JSON file. |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: JSON file data as dictionary. |
Source code in src/potato_util/io/_sync.py
read_toml_file(file_path)
Read TOML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
(str | Path, required)
|
TOML file path. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If TOML file is not found. |
Exception
|
If failed to read TOML file. |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: TOML file data as dictionary. |
Source code in src/potato_util/io/_sync.py
read_yaml_file(file_path)
Read YAML file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
(str | Path, required)
|
YAML file path. |
required |
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If YAML file is not found. |
Exception
|
If failed to read YAML file. |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
dict[str, Any]: YAML file data as dictionary. |
Source code in src/potato_util/io/_sync.py
remove_dir(remove_dir, warn_mode=WarnEnum.DEBUG)
Remove directory if remove_dir exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
remove_dir
|
(str, required)
|
Remove directory path. |
required |
warn_mode
|
WarnEnum | str
|
Warning message mode, for example: 'ERROR', 'ALWAYS', 'DEBUG', 'IGNORE'. Defaults to 'DEBUG'. |
DEBUG
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
OSError
|
When warning mode is set to ERROR and directory doesn't exist. |
OSError
|
If failed to remove directory. |
Source code in src/potato_util/io/_sync.py
remove_dirs(remove_dirs, warn_mode=WarnEnum.DEBUG)
Remove directories if remove_dirs exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
remove_dirs
|
(list[str], required)
|
Remove directory paths as list. |
required |
warn_mode
|
WarnEnum | str
|
Warning message mode, for example: 'ERROR', 'ALWAYS', 'DEBUG', 'IGNORE'. Defaults to 'DEBUG'. |
DEBUG
|
Source code in src/potato_util/io/_sync.py
remove_file(file_path, warn_mode=WarnEnum.DEBUG)
Remove file if file_path exists.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
(str, required)
|
Remove file path. |
required |
warn_mode
|
WarnEnum | str
|
Warning message mode, for example: 'ERROR', 'ALWAYS', 'DEBUG', 'IGNORE'. Defaults to 'DEBUG'. |
DEBUG
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
OSError
|
When warning mode is set to ERROR and file doesn't exist. |
OSError
|
If failed to remove file. |
Source code in src/potato_util/io/_sync.py
remove_files(file_paths, warn_mode=WarnEnum.DEBUG)
Remove files if file_paths exist.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_paths
|
(list[str], required)
|
Remove file paths as list. |
required |
warn_mode
|
WarnEnum | str
|
Warning message mode, for example: 'ERROR', 'ALWAYS', 'DEBUG', 'IGNORE'. Defaults to 'DEBUG'. |
DEBUG
|