Skip to content

Commit

Permalink
Move argparse code into separate argparse modules
Browse files Browse the repository at this point in the history
  • Loading branch information
shivam committed Apr 3, 2023
1 parent 6190c6d commit 228ebda
Show file tree
Hide file tree
Showing 14 changed files with 902 additions and 841 deletions.
34 changes: 18 additions & 16 deletions kcidb/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import logging
from kcidb.misc import LIGHT_ASSERTS
# Silence flake8 "imported but unused" warning
from kcidb import io, db, mq, orm, oo, monitor, tests, unittest, misc # noqa
from kcidb import io, db, mq, orm, oo, monitor, tests, unittest, misc, argparse # noqa


# Module's logger
Expand Down Expand Up @@ -184,7 +184,7 @@ def submit_main():
sys.excepthook = misc.log_and_print_excepthook
description = \
'kcidb-submit - Submit Kernel CI reports, print submission IDs'
parser = misc.ArgumentParser(description=description)
parser = argparse.ArgumentParser(description=description)
parser.add_argument(
'-p', '--project',
help='ID of the Google Cloud project containing the message queue',
Expand Down Expand Up @@ -214,8 +214,9 @@ def query_main():
sys.excepthook = misc.log_and_print_excepthook
description = \
"kcidb-query - Query Kernel CI reports"
parser = db.QueryArgumentParser(driver_types=db.DRIVER_TYPES,
description=description)
parser = db.argparse.QueryArgumentParser(
driver_types=db.DRIVER_TYPES,
description=description)
args = parser.parse_args()
client = Client(database=args.database)
query_iter = client.query_iter(
Expand All @@ -237,8 +238,8 @@ def schema_main():
"""Execute the kcidb-schema command-line tool"""
sys.excepthook = misc.log_and_print_excepthook
description = 'kcidb-schema - Output current or older I/O JSON schema'
parser = misc.OutputArgumentParser(description=description)
misc.argparse_schema_add_args(parser, "output")
parser = argparse.OutputArgumentParser(description=description)
argparse.schema_add_args(parser, "output")
args = parser.parse_args()
misc.json_dump(args.schema_version.json, sys.stdout, indent=args.indent,
seq=args.seq)
Expand All @@ -248,8 +249,8 @@ def validate_main():
"""Execute the kcidb-validate command-line tool"""
sys.excepthook = misc.log_and_print_excepthook
description = 'kcidb-validate - Validate I/O JSON data'
parser = misc.OutputArgumentParser(description=description)
misc.argparse_schema_add_args(parser, "validate against")
parser = argparse.OutputArgumentParser(description=description)
argparse.schema_add_args(parser, "validate against")
args = parser.parse_args()
misc.json_dump_stream(
(
Expand All @@ -264,8 +265,8 @@ def upgrade_main():
"""Execute the kcidb-upgrade command-line tool"""
sys.excepthook = misc.log_and_print_excepthook
description = 'kcidb-upgrade - Upgrade I/O JSON data to current schema'
parser = misc.OutputArgumentParser(description=description)
misc.argparse_schema_add_args(parser, "upgrade")
parser = argparse.OutputArgumentParser(description=description)
argparse.schema_add_args(parser, "upgrade")
args = parser.parse_args()
misc.json_dump_stream(
(
Expand All @@ -280,7 +281,7 @@ def count_main():
"""Execute the kcidb-count command-line tool"""
sys.excepthook = misc.log_and_print_excepthook
description = 'kcidb-count - Count number of objects in I/O JSON data'
parser = misc.ArgumentParser(description=description)
parser = argparse.ArgumentParser(description=description)
parser.parse_args()

for data in misc.json_load_stream_fd(sys.stdin.fileno()):
Expand All @@ -292,7 +293,7 @@ def merge_main():
"""Execute the kcidb-merge command-line tool"""
sys.excepthook = misc.log_and_print_excepthook
description = 'kcidb-merge - Upgrade and merge I/O data sets'
parser = misc.OutputArgumentParser(description=description)
parser = argparse.OutputArgumentParser(description=description)
args = parser.parse_args()

sources = [
Expand All @@ -312,7 +313,8 @@ def notify_main():
"""Execute the kcidb-notify command-line tool"""
sys.excepthook = misc.log_and_print_excepthook
description = 'kcidb-notify - Generate notifications for specified objects'
parser = oo.ArgumentParser(database="json", description=description)
parser = oo.argparse.ArgumentParser(database="json",
description=description)
args = parser.parse_args()
oo_client = oo.Client(db.Client(args.database))
pattern_set = set()
Expand All @@ -332,9 +334,9 @@ def ingest_main():
sys.excepthook = misc.log_and_print_excepthook
description = 'kcidb-ingest - Load data into a (new) database and ' \
'generate notifications for new and modified objects'
parser = db.ArgumentParser(driver_types=db.DRIVER_TYPES,
database="sqlite::memory:",
description=description)
parser = db.argparse.ArgumentParser(driver_types=db.DRIVER_TYPES,
database="sqlite::memory:",
description=description)
args = parser.parse_args()

db_client = db.Client(args.database)
Expand Down
Loading

0 comments on commit 228ebda

Please sign in to comment.