From f09919ca62bb07327cff0a919205bea9d293fadf Mon Sep 17 00:00:00 2001 From: Fisch Date: Mon, 22 Jul 2024 14:57:18 +0200 Subject: [PATCH] add deletion flag and verification --- logdata_visualization/copyLogsFromBobbycar.py | 43 +++++++++++++++---- 1 file changed, 35 insertions(+), 8 deletions(-) diff --git a/logdata_visualization/copyLogsFromBobbycar.py b/logdata_visualization/copyLogsFromBobbycar.py index b7022c3..f1bd846 100644 --- a/logdata_visualization/copyLogsFromBobbycar.py +++ b/logdata_visualization/copyLogsFromBobbycar.py @@ -2,6 +2,10 @@ import serial import os import time +import random +import string + +import argparse chunksize=4096 #LOG0002 @@ -150,6 +154,20 @@ def delete_file(filename): if __name__ == "__main__": + + + parser = argparse.ArgumentParser(description='Transfers log files from bobbycar over serial') + parser.add_argument('-o', '--output', nargs='?', help="output directory") + parser.add_argument('-d','--delete', action="store_true", help="delete files after transfer") + args = parser.parse_args() + outputfolder="sdcard" + if (args.output is not None): + outputfolder = args.output + if(outputfolder[-1]=='/'): + outputfolder=outputfolder[:-1] #remove last slash + print("Outputfolder:"+outputfolder) + + if serialport.isOpen(): establish_connection() @@ -169,7 +187,7 @@ if __name__ == "__main__": expectedsize=get_filesize(filename) print("Expecting "+str(expectedsize)+" Byte") - writefilename='sdcard/'+filename + writefilename=outputfolder+'/'+filename receivedsize=copy_file(filename,writefilename,expectedsize) if (expectedsize!=receivedsize): @@ -182,13 +200,22 @@ if __name__ == "__main__": - #Delete all files - - ''' - log_off() - for filename in filenames: - delete_file(filename) - ''' + #Delete all files + if (args.delete): + if (failed>0): + print("Copy not successful. Files won't be deleted!") + exit() + deletecheckstring=''.join(random.choices(string.ascii_lowercase, k=3)) + deletecheck=input("Enter "+deletecheckstring+" to confirm deletion of "+str(len(filenames))+" files on bobbycar:") + + if (deletecheck==deletecheckstring): + log_off() + for filename in filenames: + print("Deleting "+filename) + delete_file(filename) + else: + print("Verification failed!") + serialport.write("echo on\n".encode())