From 0377f322d70510eaa8cb74d22f95479ec6323ce6 Mon Sep 17 00:00:00 2001 From: theStack Date: Sun, 31 Jan 2010 15:21:15 +0100 Subject: [PATCH] check for argument "-d" if len(argv) is 4 we can use getopt (http://docs.python.org/library/getopt.html) instead of manual parsing if the number of options increases in the future... --- frprog.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/frprog.py b/frprog.py index d99f48f..f87dbc0 100755 --- a/frprog.py +++ b/frprog.py @@ -177,6 +177,9 @@ def readMHXFile(filename): # desired mhx filename fp.close() return retval +def usage(execfile): + print "Usage: " + execfile + " [-d DEVICE]" + def main(argv=None): # check command line arguments if argv is None: @@ -187,13 +190,19 @@ def main(argv=None): return 0 if len(argv) != 2 and len(argv) != 4: - print "Usage: " + argv[0] + " [-d DEVICE]" + usage(argv[0]) return 1 # standard serial device to communicate with DEVICE="/dev/ttyUSB0" + + # overrule standard device if provided with -d if len(argv) == 4: - DEVICE = argv[3] + if argv[2] == "-d": + DEVICE = argv[3] + else: + usage(argv[0]) + return 1 # read in data from mhx-files before starting try: -- 2.25.1