add deletion flag and verification
This commit is contained in:
parent
f3775e7d01
commit
f09919ca62
|
@ -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):
|
||||
|
@ -183,12 +201,21 @@ if __name__ == "__main__":
|
|||
|
||||
|
||||
#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!")
|
||||
|
||||
'''
|
||||
log_off()
|
||||
for filename in filenames:
|
||||
delete_file(filename)
|
||||
'''
|
||||
|
||||
|
||||
serialport.write("echo on\n".encode())
|
||||
|
|
Loading…
Reference in New Issue