From 24a5a97cfb3caf0baac939865c60000874ee9415 Mon Sep 17 00:00:00 2001 From: Fisch Date: Mon, 15 Jul 2024 19:24:19 +0200 Subject: [PATCH] add automatic consecuitve filename adding --- logdata_visualization/logfix.py | 50 +++++++++++++++++++++++++++++++-- 1 file changed, 47 insertions(+), 3 deletions(-) diff --git a/logdata_visualization/logfix.py b/logdata_visualization/logfix.py index 745f559..fc019f7 100644 --- a/logdata_visualization/logfix.py +++ b/logdata_visualization/logfix.py @@ -2,12 +2,16 @@ import numpy as np from datetime import datetime import time import argparse +import os.path parser = argparse.ArgumentParser(description='Copys, renames and fixes logfiles written by bobbycar sd logger.') -parser.add_argument('--input', type=argparse.FileType('r'), nargs='+') -parser.add_argument('--output', nargs='?', type=argparse.FileType('w')) +parser.add_argument('-i', '--input', type=argparse.FileType('r'), nargs='+', required=True, help="list of input log files") +parser.add_argument('-o', '--output', nargs='?', type=argparse.FileType('w'), help="output filename") +parser.add_argument('-c','--consecutive', action="store_true", help="add consecutive files to input. If the input file ends with a number the following logfiles will be added.") args = parser.parse_args() + + ok=True def getTimestamp(plines): @@ -71,8 +75,48 @@ def filterLines(plines,plinesStarttime=None): return plines,pheader,pcommentlinesMask,pdatalines,pdatalinesFail,pdatalinesOK,pheaderSize,plinesOK,plinesStarttime +inputFilenames=[] + +if (args.consecutive): + if(len(args.input)!=1): + parser.error("in consequtive mode exactly one input file is required") + exit() + + nextFilename=args.input[0].name + while os.path.isfile(nextFilename): + print(nextFilename+" exists") + inputFilenames.append(nextFilename) + + digitStartpos=len(nextFilename)-1 + digitEndpos=len(nextFilename) + + + + while (not nextFilename[digitStartpos:digitEndpos].isdigit() and digitStartpos>0 and digitEndpos>0): + digitStartpos-=1 + digitEndpos-=1 + + while (nextFilename[digitStartpos:digitEndpos].isdigit() and digitStartpos>0 and digitEndpos>0): + digitStartpos-=1 + + digitStartpos+=1 + + + number=int(nextFilename[digitStartpos:digitEndpos])+1 + nextFilename=nextFilename[0:digitStartpos]+str(number).zfill(digitEndpos-digitStartpos)+nextFilename[digitEndpos:] + + + + print("") + print(inputFilenames) + + +else: + inputFilenames=[x.name for x in args.input] + + + -inputFilenames=[x.name for x in args.input] outputFilename=None if args.output is not None: