From: Jens Steinhauser Date: Wed, 19 Nov 2014 16:44:45 +0000 (+0100) Subject: Shorten argument parsing. X-Git-Url: https://sigrok.org/gitaction?a=commitdiff_plain;h=4ce8c1c0b13d98e9929ea1ebe858da7d905a038b;p=sigrok-meter.git Shorten argument parsing. --- diff --git a/sigrok-meter b/sigrok-meter index 72b8d49..546c8b2 100755 --- a/sigrok-meter +++ b/sigrok-meter @@ -27,7 +27,7 @@ import sys import textwrap default_drivers = ['demo:analog_channels=4'] -default_loglevel = sr.LogLevel.WARN +default_loglevel = 2 def parse_cli(): parser = argparse.ArgumentParser( @@ -48,6 +48,7 @@ def parse_cli(): help='The driver to use') parser.add_argument('-l', '--loglevel', type=int, + default=default_loglevel, help='Set loglevel (5 is most verbose)') parser.add_argument('--pyside', action='store_true', @@ -55,37 +56,29 @@ def parse_cli(): help='Force use of PySide (default is to use PyQt4)') args = parser.parse_args() - result = { - 'drivers': default_drivers, - 'loglevel': default_loglevel, - 'pyside': args.pyside - } + if not args.driver: + args.driver = default_drivers - if args.driver: - result['drivers'] = args.driver - - if args.loglevel != None: - try: - result['loglevel'] = sr.LogLevel.get(args.loglevel) - except: - sys.exit('error: invalid log level') - - return result + return args if __name__ == '__main__': args = parse_cli() import qtcompat - qtcompat.load_modules(args['pyside']) + qtcompat.load_modules(args.pyside) QtCore = qtcompat.QtCore QtGui = qtcompat.QtGui import mainwindow context = sr.Context_create() - context.log_level = args['loglevel'] + try: + loglevel = sr.LogLevel.get(args.loglevel) + context.log_level = loglevel + except: + sys.exit('error: invalid log level') app = QtGui.QApplication([]) - s = mainwindow.MainWindow(context, args['drivers']) + s = mainwindow.MainWindow(context, args.driver) s.show() sys.exit(app.exec_())