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
91from __future__ import print_function91from __future__ import print_function
92 92
93import sys93import sys
94import argparse
94import weakref95import weakref
95import threading96import threading
96import string97import string
@@ -3361,18 +3362,26 @@ class DBRef(): · 3264 unmodified lines
3361# Main3362# Main
3362 3363
3363def Main():3364def Main():
3364 if (len(sys.argv) < 2):3365 usage_str = "exported-sql-viewer.py [--pyside-version-1] <database name>\n" \
3365 printerr("Usage is: exported-sql-viewer.py {<database name> | --help-only}");3366 " or: exported-sql-viewer.py --help-only"
3366 raise Exception("Too few arguments")3367 ap = argparse.ArgumentParser(usage = usage_str, add_help = False)
3367 3368 ap.add_argument("dbname", nargs="?")
3368 dbname = sys.argv[1]3369 ap.add_argument("--help-only", action='store_true')
3369 if dbname == "--help-only":3370 args = ap.parse_args()
3371
3372 if args.help_only:
3370 app = QApplication(sys.argv)3373 app = QApplication(sys.argv)
3371 mainwindow = HelpOnlyWindow()3374 mainwindow = HelpOnlyWindow()
3372 mainwindow.show()3375 mainwindow.show()
3373 err = app.exec_()3376 err = app.exec_()
3374 sys.exit(err)3377 sys.exit(err)
3375 3378
3379 dbname = args.dbname
3380 if dbname is None:
3381 ap.print_usage()
3382 print("Too few arguments")
3383 sys.exit(1)
3384
3376 is_sqlite3 = False3385 is_sqlite3 = False
3377 try:3386 try:
3378 f = open(dbname, "rb")3387 f = open(dbname, "rb")