Allow to customize glob and location in command question and hist, convert location type to enum.
This commit is contained in:
@@ -2,7 +2,7 @@ import sys
|
||||
import argparse
|
||||
from pathlib import Path
|
||||
from ..configuration import Config
|
||||
from ..chat import ChatDB
|
||||
from ..chat import ChatDB, msg_location
|
||||
from ..message import MessageFilter, Message
|
||||
|
||||
|
||||
@@ -15,9 +15,10 @@ def convert_messages(args: argparse.Namespace, config: Config) -> None:
|
||||
('.txt', '.yaml') to the latest default message file suffix ('.msg').
|
||||
"""
|
||||
chat = ChatDB.from_dir(Path(config.cache),
|
||||
Path(config.db))
|
||||
Path(config.db),
|
||||
glob='*')
|
||||
# read all known message files
|
||||
msgs = chat.msg_gather(loc='disk', glob='*.*')
|
||||
msgs = chat.msg_gather(loc=msg_location.DISK, glob='*.*')
|
||||
# make a set of all message IDs
|
||||
msg_ids = set([m.msg_id() for m in msgs])
|
||||
# set requested format and write all messages
|
||||
@@ -29,14 +30,14 @@ def convert_messages(args: argparse.Namespace, config: Config) -> None:
|
||||
m.file_path = m.file_path.with_suffix('')
|
||||
chat.msg_write(msgs)
|
||||
# read all messages with the current default suffix
|
||||
msgs = chat.msg_gather(loc='disk', glob=f'*{msg_suffix}')
|
||||
msgs = chat.msg_gather(loc=msg_location.DISK, glob=f'*{msg_suffix}')
|
||||
# make sure we converted all of the original messages
|
||||
for mid in msg_ids:
|
||||
if not any(mid == m.msg_id() for m in msgs):
|
||||
print(f"Message '{mid}' has not been found after conversion. Aborting.")
|
||||
sys.exit(1)
|
||||
# delete messages with old suffixes
|
||||
msgs = chat.msg_gather(loc='disk', glob='*.*')
|
||||
msgs = chat.msg_gather(loc=msg_location.DISK, glob='*.*')
|
||||
for m in msgs:
|
||||
if m.file_path and m.file_path.suffix != msg_suffix:
|
||||
m.rm_file()
|
||||
@@ -55,7 +56,9 @@ def print_chat(args: argparse.Namespace, config: Config) -> None:
|
||||
answer_contains=args.answer)
|
||||
chat = ChatDB.from_dir(Path(config.cache),
|
||||
Path(config.db),
|
||||
mfilter=mfilter)
|
||||
mfilter=mfilter,
|
||||
loc=msg_location(args.location),
|
||||
glob=args.glob)
|
||||
chat.print(args.source_code_only,
|
||||
args.with_metadata,
|
||||
paged=not args.no_paging,
|
||||
|
||||
Reference in New Issue
Block a user