Utils
sereto.utils
¶
assert_file_size_within_range(file, max_bytes, min_bytes=0, interactive=False)
¶
Evaluates if the file size is within the specified range.
If interactive
is True, the user is first prompted whether to continue if the file size is not within the range.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
FilePath
|
The path to the file. |
required |
max_bytes
|
int
|
The maximum file size in bytes. |
required |
min_bytes
|
int
|
The minimum file size in bytes. Defaults to 0. |
0
|
interactive
|
bool
|
If True, the user is prompted whether to continue if the file size is not within the range. Defaults to False. |
False
|
Raises:
Type | Description |
---|---|
SeretoPathError
|
If the file does not exist. |
SeretoValueError
|
If the file size is not within the specified range. |
Source code in sereto/utils.py
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
replace_strings(text, replacements)
¶
replace_strings(text: str, replacements: dict[str, str]) -> str
replace_strings(text: list[str], replacements: dict[str, str]) -> list[str]
One-pass string replacement with values from dictionary.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
text
|
str | list[str]
|
The input text. |
required |
replacements
|
dict[str, str]
|
Dictionary with replacements. Key-value in dictionary refers to pattern string and replacement string, respectively. |
required |
Returns:
Type | Description |
---|---|
str | list[str]
|
String (or list of strings, depending on the input value) obtained by applying the replacements from the
|
Source code in sereto/utils.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
|
write_if_different(file, content)
¶
Writes content to file only if the content is different from the existing file content.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
file
|
Path
|
The path to the file. |
required |
content
|
str
|
The content to write to the file. |
required |
Returns:
Type | Description |
---|---|
bool
|
True if new content was written to the file, False otherwise. |
Source code in sereto/utils.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|