From 72d3867820b9a48ba03d94ef6661ae669297fe6d Mon Sep 17 00:00:00 2001 From: zqb-all Date: Wed, 17 Oct 2018 23:40:52 +0800 Subject: [PATCH 1/3] test: fix trailing spaces Signed-off-by: zqb-all --- test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test.sh b/test.sh index 45777a5..96bd3a4 100755 --- a/test.sh +++ b/test.sh @@ -63,7 +63,7 @@ echo " 120 second grab, try logging in (test user input to serial port)" # run for two minutes, allowing user to login (using threaded input) ./grabserial -v -S -d ${console_dev} -e 120 -t -o graboutput2.log -echo +echo echo "Testing with python 3" echo " 60 second grab, stopping when 'login' is seen" @@ -77,6 +77,6 @@ echo " 120 second grab, try logging in (test user input to serial port)" (sleep 1 ; ttc reboot bbb) & python3 ./grabserial -v -S -d ${console_dev} -e 120 -t -o graboutput4.log -echo +echo echo "Done in test.sh" From 247f653bced2eaaef11a162dcfad03eb922a21a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20M=C4=85ka?= Date: Fri, 15 Feb 2019 12:19:21 +0100 Subject: [PATCH 2/3] Added nodelta option, added possibility to specify system time format --- grabserial | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/grabserial b/grabserial index e41ba3a..35d2e7c 100755 --- a/grabserial +++ b/grabserial @@ -118,9 +118,12 @@ options: received by %s -a, --again Restart application after -e expires or -q is triggered. - -T, --systime Print system time for each line received. The time + -T [format], --systime Print system time for each line received. The time is the absolute local time when the first character - of each line is received by %s + of each line is received by %s it's format could be + specified only using short version of flag, e.g. + -T \"%%Y-%%m-%%d %%H:%%M%%S.%%f\" + (default \"%%H:%%M:%%S.%%f\") -m, --match= Specify a regular expression pattern to match to set a base time. Time values for lines after the line matching the pattern will be relative to @@ -138,6 +141,7 @@ options: -V, --version Show version number and exit -S, --skip Skip sanity checking of the serial device. May be needed for some devices. + -n, --nodelta Skip printing delta between read lines. --crtonewline Promote a carriage return to be treated as a newline @@ -208,7 +212,7 @@ def grab(arglist, outputfd=sys.stdout): try: opts, args = getopt.getopt( arglist, - "hli:d:b:B:w:p:s:xrfc:taTm:e:o:QvVq:S", [ + "hli:d:b:B:w:p:s:xrfc:taT:m:e:o:QvVq:nS", [ "help", "launchtime", "instantpat=", @@ -231,6 +235,7 @@ def grab(arglist, outputfd=sys.stdout): "verbose", "version", "quitpat=", + "nodelta", "skip", "crtonewline", ]) @@ -266,6 +271,8 @@ def grab(arglist, outputfd=sys.stdout): cr_to_nl = 0 restart = False quiet = False + systime_format = "%H:%M:%S.%f" + use_delta = True for opt, arg in opts: if opt in ["-h", "--help"]: @@ -329,6 +336,8 @@ def grab(arglist, outputfd=sys.stdout): if opt in ["-a", "--again"]: restart = True if opt in ["-T", "--systime"]: + if arg: + systime_format = arg show_time = 0 show_systime = 1 if opt in ["-m", "--match"]: @@ -362,8 +371,10 @@ def grab(arglist, outputfd=sys.stdout): print("grabserial version %d.%d.%d" % VERSION) sd.close() sys.exit(0) - if opt in ["-S"]: + if opt in ["-S", "--skip"]: skip_device_check = 1 + if opt in ["-n", "--nodelta"]: + use_delta = False if opt in ["--crtonewline"]: cr_to_nl = 1 @@ -497,10 +508,13 @@ def grab(arglist, outputfd=sys.stdout): if show_systime and newline: linetime = time.time() - linetimestr = datetime.datetime.now().strftime("%H:%M:%S.%f") + linetimestr = datetime.datetime.now().strftime(systime_format) elapsed = linetime-basetime - delta = elapsed-prev1 - msg = "[%s %2.6f] " % (linetimestr, delta) + if use_delta: + delta = elapsed-prev1 + msg = "[%s %2.6f] " % (linetimestr, delta) + else: + msg = "[%s] " % (linetimestr) if not quiet: outputfd.write(msg) if out: From e099178bc677e366641b1f1e7a67ed9767ffafa5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20M=C4=85ka?= Date: Fri, 15 Feb 2019 14:19:22 +0100 Subject: [PATCH 3/3] System time format was moved to other option --- grabserial | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/grabserial b/grabserial index 35d2e7c..0fd6005 100755 --- a/grabserial +++ b/grabserial @@ -118,11 +118,12 @@ options: received by %s -a, --again Restart application after -e expires or -q is triggered. - -T [format], --systime Print system time for each line received. The time + -T, --systime Print system time for each line received. The time is the absolute local time when the first character - of each line is received by %s it's format could be - specified only using short version of flag, e.g. - -T \"%%Y-%%m-%%d %%H:%%M%%S.%%f\" + of each line is received by %s + -F, --timeformat= Specifies system time format for each received line + e.g. + -F \"%%Y-%%m-%%d %%H:%%M%%S.%%f\" (default \"%%H:%%M:%%S.%%f\") -m, --match= Specify a regular expression pattern to match to set a base time. Time values for lines after the @@ -212,7 +213,7 @@ def grab(arglist, outputfd=sys.stdout): try: opts, args = getopt.getopt( arglist, - "hli:d:b:B:w:p:s:xrfc:taT:m:e:o:QvVq:nS", [ + "hli:d:b:B:w:p:s:xrfc:taTF:m:e:o:QvVq:nS", [ "help", "launchtime", "instantpat=", @@ -228,6 +229,7 @@ def grab(arglist, outputfd=sys.stdout): "time", "again", "systime", + "timeformat=", "match=", "endtime=", "output=", @@ -336,10 +338,10 @@ def grab(arglist, outputfd=sys.stdout): if opt in ["-a", "--again"]: restart = True if opt in ["-T", "--systime"]: - if arg: - systime_format = arg show_time = 0 show_systime = 1 + if opt in ["-F", "--timeformat"]: + systime_format = arg if opt in ["-m", "--match"]: basepat = arg if opt in ["-i", "--instantpat"]: