History

perf scripts python: exported-sql-viewer.py: Use argparse module for argument parsing

The argparse module makes it easier to add new arguments.

Adrian Hunter committed 7 years ago

Commit 1ed7f471 parent c6aba1b1 file · +15 −6Browse files

Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all

Unified · Split

tools/perf/scripts/python/exported-sql-viewer.py+15−6
@@ -91,6 +91,7 @@ · 90 unmodified lines
9191 from __future__ import print_function
9292
9393 import sys
94+import argparse
9495 import weakref
9596 import threading
9697 import string
@@ -3361,18 +3362,26 @@ class DBRef(): · 3264 unmodified lines
33613362 # Main
33623363
33633364 def Main():
3364− if (len(sys.argv) < 2):
3365− printerr("Usage is: exported-sql-viewer.py {<database name> | --help-only}");
3366− raise Exception("Too few arguments")
3367−
3368− dbname = sys.argv[1]
3369− if dbname == "--help-only":
3365+ usage_str = "exported-sql-viewer.py [--pyside-version-1] <database name>\n" \
3366+ " or: exported-sql-viewer.py --help-only"
3367+ ap = argparse.ArgumentParser(usage = usage_str, add_help = False)
3368+ ap.add_argument("dbname", nargs="?")
3369+ ap.add_argument("--help-only", action='store_true')
3370+ args = ap.parse_args()
3371+
3372+ if args.help_only:
33703373 app = QApplication(sys.argv)
33713374 mainwindow = HelpOnlyWindow()
33723375 mainwindow.show()
33733376 err = app.exec_()
33743377 sys.exit(err)
33753378
3379+ dbname = args.dbname
3380+ if dbname is None:
3381+ ap.print_usage()
3382+ print("Too few arguments")
3383+ sys.exit(1)
3384+
33763385 is_sqlite3 = False
33773386 try:
33783387 f = open(dbname, "rb")