Skip to content

Commit

Permalink
db: Add kcidb-db-time command-line tool
Browse files Browse the repository at this point in the history
  • Loading branch information
spbnick committed Nov 6, 2024
1 parent 185c939 commit d47ae47
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
29 changes: 29 additions & 0 deletions kcidb/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1070,3 +1070,32 @@ def purge_main():
if not client.is_initialized():
raise Exception(f"Database {args.database!r} is not initialized")
return 0 if client.purge(before=args.before) else 2


def time_main():
"""Execute the kcidb-db-time command-line tool"""
sys.excepthook = kcidb.misc.log_and_print_excepthook
description = 'kcidb-db-time - Fetch various timestamps from a KCIDB DB'
parser = ArgumentParser(description=description)
parser.add_argument(
'type',
choices=['first_modified', 'last_modified', 'current'],
help="The type of timestamp to retrieve."
)
args = parser.parse_args()
client = Client(args.database)
if not client.is_initialized():
raise Exception(f"Database {args.database!r} is not initialized")
ts = None
if args.type == 'first_modified':
ts = client.get_first_modified()
elif args.type == 'last_modified':
ts = client.get_last_modified()
elif args.type == 'current':
ts = client.get_current_time()
if ts is None:
print("The database is empty, cannot retrieve modification time",
file=sys.stderr)
return 1
print(ts.isoformat(timespec='microseconds'))
return 0
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
"kcidb-db-load = kcidb.db:load_main",
"kcidb-db-dump = kcidb.db:dump_main",
"kcidb-db-query = kcidb.db:query_main",
"kcidb-db-time = kcidb.db:time_main",
"kcidb-mq-email-publisher = kcidb.mq:email_publisher_main",
"kcidb-mq-email-subscriber = kcidb.mq:email_subscriber_main",
"kcidb-mq-io-publisher = kcidb.mq:io_publisher_main",
Expand Down

0 comments on commit d47ae47

Please sign in to comment.