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 * `-O, --overwrite`: Overwrite existing messages when repeating them
* `-s, --source-text FILE`: Add content of a file to the query * `-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 * `-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 #### Hist

View File

@ -52,7 +52,7 @@ def read_dir(dir_path: Path,
Parameters: Parameters:
* 'dir_path': source directory * 'dir_path': source directory
* 'glob': if specified, files will be filtered using 'path.glob()', * '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 * 'mfilter': use with 'Message.from_file()' to filter messages
when reading them. when reading them.
""" """
@ -295,7 +295,7 @@ class ChatDB(Chat):
# a MessageFilter that all messages must match (if given) # a MessageFilter that all messages must match (if given)
mfilter: Optional[MessageFilter] = None mfilter: Optional[MessageFilter] = None
# the glob pattern for all messages # the glob pattern for all messages
glob: Optional[str] = None glob: str = f'*{msg_suffix}'
# message format (for writing) # message format (for writing)
mformat: MessageFormat = Message.default_format mformat: MessageFormat = Message.default_format
@ -311,7 +311,7 @@ class ChatDB(Chat):
def from_dir(cls: Type[ChatDBInst], def from_dir(cls: Type[ChatDBInst],
cache_path: Path, cache_path: Path,
db_path: Path, db_path: Path,
glob: Optional[str] = None, glob: str = f'*{msg_suffix}',
mfilter: Optional[MessageFilter] = None, mfilter: Optional[MessageFilter] = None,
loc: msg_location = msg_location.DB) -> ChatDBInst: loc: msg_location = msg_location.DB) -> ChatDBInst:
""" """
@ -320,10 +320,10 @@ class ChatDB(Chat):
Parameters: Parameters:
* 'cache_path': path to the directory for temporary messages * 'cache_path': path to the directory for temporary messages
* 'db_path': path to the directory for persistent messages * 'db_path': path to the directory for persistent messages
* 'glob': if specified, files will be filtered using 'path.glob()', * 'glob': if specified, files will be filtered using 'path.glob()'
otherwise it uses 'path.iterdir()'.
* 'mfilter': use with 'Message.from_file()' to filter messages * 'mfilter': use with 'Message.from_file()' to filter messages
when reading them. when reading them.
* 'loc': read messages from given location instead of 'db_path'
""" """
messages: list[Message] = [] messages: list[Message] = []
if loc in [msg_location.DB, msg_location.DISK, msg_location.ALL]: if loc in [msg_location.DB, msg_location.DISK, msg_location.ALL]:
@ -400,7 +400,7 @@ class ChatDB(Chat):
def msg_gather(self, def msg_gather(self,
loc: msg_location, loc: msg_location,
require_file_path: bool = False, require_file_path: bool = False,
glob: Optional[str] = None, glob: str = f'*{msg_suffix}',
mfilter: Optional[MessageFilter] = None) -> list[Message]: mfilter: Optional[MessageFilter] = None) -> list[Message]:
""" """
Gather and return messages from the given locations: Gather and return messages from the given locations:
@ -520,7 +520,7 @@ class ChatDB(Chat):
else: else:
return len(self.msg_find([message], loc=msg_location.DB)) > 0 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, 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 existing ones are replaced. A message is determined as 'existing' if a message
@ -563,7 +563,7 @@ class ChatDB(Chat):
self.messages += messages self.messages += messages
self.msg_sort() 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. 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 # (re)add it to the internal list
self.msg_add([message]) 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, 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 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', hist_cmd_parser.add_argument('-l', '--location',
choices=[x.value for x in msg_location], choices=[x.value for x in msg_location],
default='db', default='db',
help='Select message location, default is \'db\'') help='Use given location when building the chat history (default: \'db\')')
hist_cmd_parser.add_argument('-g', '--glob', help='Glob for message file names') hist_cmd_parser.add_argument('-g', '--glob', help='Filter message files using the given glob pattern')
# 'tags' command parser # 'tags' command parser
tags_cmd_parser = cmdparser.add_parser('tags', tags_cmd_parser = cmdparser.add_parser('tags',