Compare commits

...

3 Commits

3 changed files with 13 additions and 11 deletions

View File

@ -65,6 +65,8 @@ cmm question [-t OTAGS]... [-k ATAGS]... [-x XTAGS]... [-o OUTTAGS]... [-A AI_ID
* `-O, --overwrite`: Overwrite existing messages when repeating them
* `-s, --source-text FILE`: Add content of a file to the query
* `-S, --source-code FILE`: Add source code file content to the chat history
* `-l, --location {disk,cache,db,all}`: Use given location when building the chat history (default: 'db')
* `-g, --glob GLOB`: Filter message files using the given glob pattern
#### Hist

View File

@ -52,7 +52,7 @@ def read_dir(dir_path: Path,
Parameters:
* 'dir_path': source directory
* 'glob': if specified, files will be filtered using 'path.glob()',
otherwise it uses '*{msg_suffix}'.
otherwise it reads all files with the default message suffix
* 'mfilter': use with 'Message.from_file()' to filter messages
when reading them.
"""
@ -295,7 +295,7 @@ class ChatDB(Chat):
# a MessageFilter that all messages must match (if given)
mfilter: Optional[MessageFilter] = None
# the glob pattern for all messages
glob: Optional[str] = None
glob: str = f'*{msg_suffix}'
# message format (for writing)
mformat: MessageFormat = Message.default_format
@ -311,7 +311,7 @@ class ChatDB(Chat):
def from_dir(cls: Type[ChatDBInst],
cache_path: Path,
db_path: Path,
glob: Optional[str] = None,
glob: str = f'*{msg_suffix}',
mfilter: Optional[MessageFilter] = None,
loc: msg_location = msg_location.DB) -> ChatDBInst:
"""
@ -320,10 +320,10 @@ class ChatDB(Chat):
Parameters:
* 'cache_path': path to the directory for temporary messages
* 'db_path': path to the directory for persistent messages
* 'glob': if specified, files will be filtered using 'path.glob()',
otherwise it uses 'path.iterdir()'.
* 'glob': if specified, files will be filtered using 'path.glob()'
* 'mfilter': use with 'Message.from_file()' to filter messages
when reading them.
* 'loc': read messages from given location instead of 'db_path'
"""
messages: list[Message] = []
if loc in [msg_location.DB, msg_location.DISK, msg_location.ALL]:
@ -400,7 +400,7 @@ class ChatDB(Chat):
def msg_gather(self,
loc: msg_location,
require_file_path: bool = False,
glob: Optional[str] = None,
glob: str = f'*{msg_suffix}',
mfilter: Optional[MessageFilter] = None) -> list[Message]:
"""
Gather and return messages from the given locations:
@ -520,7 +520,7 @@ class ChatDB(Chat):
else:
return len(self.msg_find([message], loc=msg_location.DB)) > 0
def cache_read(self, glob: Optional[str] = None, mfilter: Optional[MessageFilter] = None) -> None:
def cache_read(self, glob: str = f'*{msg_suffix}', mfilter: Optional[MessageFilter] = None) -> None:
"""
Read messages from the cache directory. New ones are added to the internal list,
existing ones are replaced. A message is determined as 'existing' if a message
@ -563,7 +563,7 @@ class ChatDB(Chat):
self.messages += messages
self.msg_sort()
def cache_clear(self, glob: Optional[str] = None) -> None:
def cache_clear(self, glob: str = f'*{msg_suffix}') -> None:
"""
Delete all message files from the cache dir and remove them from the internal list.
"""
@ -587,7 +587,7 @@ class ChatDB(Chat):
# (re)add it to the internal list
self.msg_add([message])
def db_read(self, glob: Optional[str] = None, mfilter: Optional[MessageFilter] = None) -> None:
def db_read(self, glob: str = f'*{msg_suffix}', mfilter: Optional[MessageFilter] = None) -> None:
"""
Read messages from the DB directory. New ones are added to the internal list,
existing ones are replaced. A message is determined as 'existing' if a message

View File

@ -96,8 +96,8 @@ def create_parser() -> argparse.ArgumentParser:
hist_cmd_parser.add_argument('-l', '--location',
choices=[x.value for x in msg_location],
default='db',
help='Select message location, default is \'db\'')
hist_cmd_parser.add_argument('-g', '--glob', help='Glob for message file names')
help='Use given location when building the chat history (default: \'db\')')
hist_cmd_parser.add_argument('-g', '--glob', help='Filter message files using the given glob pattern')
# 'tags' command parser
tags_cmd_parser = cmdparser.add_parser('tags',