add automatic consecuitve filename adding

This commit is contained in:
interfisch 2024-07-15 19:24:19 +02:00
parent 3c5cd0b1c3
commit 24a5a97cfb
1 changed files with 47 additions and 3 deletions

View File

@ -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,9 +75,49 @@ 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]
outputFilename=None
if args.output is not None:
outputFilename=args.output.name