Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

db: Add kcidb-db-time command-line tool #602

Merged
merged 1 commit into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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