chat et al: '.next' and '.config.yaml' are now ignored by ChatDB

This commit is contained in:
2023-09-14 12:45:11 +02:00
parent 5cb88dad1b
commit 071871f929
4 changed files with 14 additions and 8 deletions
+10 -4
View File
@@ -7,12 +7,16 @@ from pprint import PrettyPrinter
from pydoc import pager
from dataclasses import dataclass
from typing import TypeVar, Type, Optional, ClassVar, Any, Callable, Literal
from .configuration import default_config_file
from .message import Message, MessageFilter, MessageError, message_in
from .tags import Tag
ChatInst = TypeVar('ChatInst', bound='Chat')
ChatDBInst = TypeVar('ChatDBInst', bound='ChatDB')
db_next_file = '.next'
ignored_files = [db_next_file, default_config_file]
class ChatError(Exception):
pass
@@ -45,7 +49,9 @@ def read_dir(dir_path: Path,
messages: list[Message] = []
file_iter = dir_path.glob(glob) if glob else dir_path.iterdir()
for file_path in sorted(file_iter):
if file_path.is_file() and file_path.suffix in Message.file_suffixes:
if (file_path.is_file()
and file_path.name not in ignored_files # noqa: W503
and file_path.suffix in Message.file_suffixes): # noqa: W503
try:
message = Message.from_file(file_path, mfilter)
if message:
@@ -235,7 +241,7 @@ class ChatDB(Chat):
def __post_init__(self) -> None:
# contains the latest message ID
self.next_fname = self.db_path / '.next'
self.next_path = self.db_path / db_next_file
# make all paths absolute
self.cache_path = self.cache_path.absolute()
self.db_path = self.db_path.absolute()
@@ -274,7 +280,7 @@ class ChatDB(Chat):
def get_next_fid(self) -> int:
try:
with open(self.next_fname, 'r') as f:
with open(self.next_path, 'r') as f:
next_fid = int(f.read()) + 1
self.set_next_fid(next_fid)
return next_fid
@@ -283,7 +289,7 @@ class ChatDB(Chat):
return 1
def set_next_fid(self, fid: int) -> None:
with open(self.next_fname, 'w') as f:
with open(self.next_path, 'w') as f:
f.write(f'{fid}')
def read_db(self) -> None: