The argparse module makes it easier to add new arguments.
Showing the changes to tools/perf/scripts/python (1 of 1 file). Show all
Unified · Split
| @@ -91,6 +91,7 @@ · 90 unmodified lines | |||
| 91 | from __future__ import print_function | 91 | from __future__ import print_function |
| 92 | 92 | ||
| 93 | import sys | 93 | import sys |
| 94 | import argparse | ||
| 94 | import weakref | 95 | import weakref |
| 95 | import threading | 96 | import threading |
| 96 | import string | 97 | import string |
| @@ -3361,18 +3362,26 @@ class DBRef(): · 3264 unmodified lines | |||
| 3361 | # Main | 3362 | # Main |
| 3362 | 3363 | ||
| 3363 | def Main(): | 3364 | def 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 = False | 3385 | is_sqlite3 = False |
| 3377 | try: | 3386 | try: |
| 3378 | f = open(dbname, "rb") | 3387 | f = open(dbname, "rb") |