Compare commits
4 Commits
ad7ef32c38
...
d3799efeb3
| Author | SHA1 | Date | |
|---|---|---|---|
| d3799efeb3 | |||
| 8e8bc6345c | |||
| 87d8be2fda | |||
| 514eb99302 |
@ -94,10 +94,11 @@ class Message():
|
|||||||
question: Question
|
question: Question
|
||||||
answer: Optional[Answer]
|
answer: Optional[Answer]
|
||||||
tags: Optional[set[Tag]]
|
tags: Optional[set[Tag]]
|
||||||
path: Optional[pathlib.Path]
|
file_path: Optional[pathlib.Path]
|
||||||
|
file_suffixes: list[str] = ['.txt', '.yaml']
|
||||||
|
|
||||||
# @classmethod
|
# @classmethod
|
||||||
# def from_file(cls: Type[MessageInst], path: pathlib.Path) -> MessageInst:
|
# def from_file(cls: Type[MessageInst], file_path: pathlib.Path) -> MessageInst:
|
||||||
# """
|
# """
|
||||||
# Create a Message from the given file. Expects the following file structure:
|
# Create a Message from the given file. Expects the following file structure:
|
||||||
# * TagLine (from 'self.tags')
|
# * TagLine (from 'self.tags')
|
||||||
@ -105,9 +106,15 @@ class Message():
|
|||||||
# * Question
|
# * Question
|
||||||
# * Answer.Header
|
# * Answer.Header
|
||||||
# """
|
# """
|
||||||
|
# if file_path:
|
||||||
|
# self.file_path = file_path
|
||||||
|
# if not self.file_path:
|
||||||
|
# raise MessageError("Got no valid path to read message")
|
||||||
|
# if self.file_path.suffix not in self.file_suffixes:
|
||||||
|
# raise MessageError(f"File type '{self.file_path.suffix}' is not supported")
|
||||||
# pass
|
# pass
|
||||||
|
|
||||||
def to_file(self, path: Optional[pathlib.Path]) -> None:
|
def to_file(self, file_path: Optional[pathlib.Path]) -> None:
|
||||||
"""
|
"""
|
||||||
Write Message to the given file. Creates the following file structure:
|
Write Message to the given file. Creates the following file structure:
|
||||||
* TagLine (from 'self.tags')
|
* TagLine (from 'self.tags')
|
||||||
@ -116,8 +123,12 @@ class Message():
|
|||||||
* Answer.Header
|
* Answer.Header
|
||||||
* Answer
|
* Answer
|
||||||
"""
|
"""
|
||||||
if not path and not self.path:
|
if file_path:
|
||||||
raise MessageError('Got no valid path to write message')
|
self.file_path = file_path
|
||||||
|
if not self.file_path:
|
||||||
|
raise MessageError("Got no valid path to write message")
|
||||||
|
if self.file_path.suffix not in self.file_suffixes:
|
||||||
|
raise MessageError(f"File type '{self.file_path.suffix}' is not supported")
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def asdict(self) -> dict[str, Any]:
|
def asdict(self) -> dict[str, Any]:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user