Compare commits
2 Commits
d64838c334
...
487898e640
| Author | SHA1 | Date | |
|---|---|---|---|
| 487898e640 | |||
| a35b751506 |
@ -16,7 +16,7 @@ ChatDBInst = TypeVar('ChatDBInst', bound='ChatDB')
|
||||
|
||||
db_next_file = '.next'
|
||||
ignored_files = [db_next_file, default_config_file]
|
||||
valid_sources = Literal['mem', 'disk', 'cache', 'db', 'all']
|
||||
msg_place = Literal['mem', 'disk', 'cache', 'db', 'all']
|
||||
|
||||
|
||||
class ChatError(Exception):
|
||||
@ -133,7 +133,7 @@ class Chat:
|
||||
error = False
|
||||
for fp in file_paths:
|
||||
if file_stems.count(fp.stem) > 1:
|
||||
print(f"ERROR: File '{fp.stem}' appears twice in the message list: {msg_paths(fp.stem)}")
|
||||
print(f"ERROR: Found multiple copies of message '{fp.stem}': {msg_paths(fp.stem)}")
|
||||
error = True
|
||||
if error:
|
||||
raise ChatError("Validation failed")
|
||||
@ -373,7 +373,7 @@ class ChatDB(Chat):
|
||||
self.msg_write(messages)
|
||||
|
||||
def msg_gather(self,
|
||||
source: valid_sources,
|
||||
source: msg_place,
|
||||
require_file_path: bool = False,
|
||||
mfilter: Optional[MessageFilter] = None) -> list[Message]:
|
||||
"""
|
||||
@ -406,14 +406,14 @@ class ChatDB(Chat):
|
||||
|
||||
def msg_find(self,
|
||||
msg_names: list[str],
|
||||
source: valid_sources = 'mem',
|
||||
source: msg_place = 'mem',
|
||||
) -> list[Message]:
|
||||
"""
|
||||
Search and return the messages with the given names. Names can either be filenames
|
||||
(with or without suffix), full paths or Message.msg_id(). Messages that can't be
|
||||
found are ignored (i. e. the caller should check the result if they require all
|
||||
messages).
|
||||
Searches one of the following sources:
|
||||
Searches one of the following places:
|
||||
* 'mem' : messages currently in memory
|
||||
* 'disk' : messages on disk (cache + DB directory), but not in memory
|
||||
* 'cache': messages in the cache directory
|
||||
@ -440,11 +440,11 @@ class ChatDB(Chat):
|
||||
|
||||
def msg_latest(self,
|
||||
mfilter: Optional[MessageFilter] = None,
|
||||
source: valid_sources = 'mem') -> Optional[Message]:
|
||||
source: msg_place = 'mem') -> Optional[Message]:
|
||||
"""
|
||||
Return the last added message (according to the file ID) that matches the given filter.
|
||||
Only consider messages with a valid file_path (except if source is 'mem').
|
||||
Searches one of the following sources:
|
||||
Searches one of the following places:
|
||||
* 'mem' : messages currently in memory
|
||||
* 'disk' : messages on disk (cache + DB directory), but not in memory
|
||||
* 'cache': messages in the cache directory
|
||||
|
||||
@ -204,9 +204,10 @@ class TestChatDB(unittest.TestCase):
|
||||
{Tag('tag4')},
|
||||
file_path=pathlib.Path('0004.txt'))
|
||||
duplicate_message.to_file(pathlib.Path(self.db_path.name, '0004.txt'))
|
||||
with self.assertRaises(ChatError):
|
||||
with self.assertRaises(ChatError) as cm:
|
||||
ChatDB.from_dir(pathlib.Path(self.cache_path.name),
|
||||
pathlib.Path(self.db_path.name))
|
||||
self.assertEqual(str(cm.exception), "Validation failed")
|
||||
|
||||
def test_from_dir(self) -> None:
|
||||
chat_db = ChatDB.from_dir(pathlib.Path(self.cache_path.name),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user