add deletion flag and verification

This commit is contained in:
interfisch 2024-07-22 14:57:18 +02:00
parent f3775e7d01
commit f09919ca62
1 changed files with 35 additions and 8 deletions

View File

@ -2,6 +2,10 @@
import serial import serial
import os import os
import time import time
import random
import string
import argparse
chunksize=4096 chunksize=4096
#LOG0002 #LOG0002
@ -150,6 +154,20 @@ def delete_file(filename):
if __name__ == "__main__": 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(): if serialport.isOpen():
establish_connection() establish_connection()
@ -169,7 +187,7 @@ if __name__ == "__main__":
expectedsize=get_filesize(filename) expectedsize=get_filesize(filename)
print("Expecting "+str(expectedsize)+" Byte") print("Expecting "+str(expectedsize)+" Byte")
writefilename='sdcard/'+filename writefilename=outputfolder+'/'+filename
receivedsize=copy_file(filename,writefilename,expectedsize) receivedsize=copy_file(filename,writefilename,expectedsize)
if (expectedsize!=receivedsize): if (expectedsize!=receivedsize):
@ -182,13 +200,22 @@ if __name__ == "__main__":
#Delete all files #Delete all files
if (args.delete):
''' if (failed>0):
log_off() print("Copy not successful. Files won't be deleted!")
for filename in filenames: exit()
delete_file(filename) 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()) serialport.write("echo on\n".encode())