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

The argparse module makes it easier to add new arguments.

Signed-off-by: Adrian Hunter <adrian.hunter@intel.com>
Cc: Jiri Olsa <jolsa@redhat.com>
Link: http://lkml.kernel.org/r/20190412113830.4126-3-adrian.hunter@intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
This commit is contained in:
Adrian Hunter 2019-04-12 14:38:24 +03:00 committed by Arnaldo Carvalho de Melo
parent c6aba1bf25
commit 1ed7f47fd3

View File

@ -91,6 +91,7 @@
from __future__ import print_function from __future__ import print_function
import sys import sys
import argparse
import weakref import weakref
import threading import threading
import string import string
@ -3361,18 +3362,26 @@ class DBRef():
# Main # Main
def Main(): def Main():
if (len(sys.argv) < 2): usage_str = "exported-sql-viewer.py [--pyside-version-1] <database name>\n" \
printerr("Usage is: exported-sql-viewer.py {<database name> | --help-only}"); " or: exported-sql-viewer.py --help-only"
raise Exception("Too few arguments") ap = argparse.ArgumentParser(usage = usage_str, add_help = False)
ap.add_argument("dbname", nargs="?")
ap.add_argument("--help-only", action='store_true')
args = ap.parse_args()
dbname = sys.argv[1] if args.help_only:
if dbname == "--help-only":
app = QApplication(sys.argv) app = QApplication(sys.argv)
mainwindow = HelpOnlyWindow() mainwindow = HelpOnlyWindow()
mainwindow.show() mainwindow.show()
err = app.exec_() err = app.exec_()
sys.exit(err) sys.exit(err)
dbname = args.dbname
if dbname is None:
ap.print_usage()
print("Too few arguments")
sys.exit(1)
is_sqlite3 = False is_sqlite3 = False
try: try:
f = open(dbname, "rb") f = open(dbname, "rb")