-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
27 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
""" | ||
For YAML files. | ||
""" | ||
|
||
import pathlib | ||
import yaml | ||
|
||
|
||
def open_config(file_path: pathlib.Path) -> "tuple[bool, dict | None]": | ||
""" | ||
Open and decode YAML file. | ||
""" | ||
try: | ||
with file_path.open("r", encoding="utf8") as file: | ||
try: | ||
config = yaml.safe_load(file) | ||
return True, config | ||
except yaml.YAMLError as exception: | ||
print(f"ERROR: Could not parse YAML file: {exception}") | ||
except FileNotFoundError as exception: | ||
print(f"ERROR: YAML file not found: {exception}") | ||
except IOError as exception: | ||
print(f"ERROR: Could not open file: {exception}") | ||
|
||
return False, None |