I'm trying to code an automatic script for uploading to the gdrive with rclone. I will not go through all the code only in this check statement, the rclone command checks files from the local folder and mounted folder something like this: rclone check "local folder" "mounted folder" --ignore existing --onlyoneway it returns in terminal some data that can't be stored in a text file or I don't now how.
def upload_check():
print(" check if all files are uploaded ")
global Error_upload
if :#I stuck here, rclone check and return true or false if all files are uploaded by name and size
Error_upload = True
return Error_upload
print("Not uploaded ")#---------------------------
else:# all good
Error_upload = False
return Error_upload
print("all files are online")#---------------------------
my question is how to properly check two directories if they are identical by all files inside and files size and returning Boolean True or False?
After a few days I come up with this complicated solution:
First I created some files and a couple of them uploaded them to the drive, also one corrupted file. Than this scrip do the job. The file logfile.txt contains a list generated with rclone
rclone check 'Local' 'gdrive' --one-way -vv -P --combined logfile.txt
this bash command will generate a logfile:
more info on rclone check help on rclone. The files with "=" are identical on local and remote destination, so we want to move them from the source folder to an uploaded folder.
The script runs again and if the read function can't read anything, all files are online and the upload function does not need to run again. But since there are un uploaded files and a corrupted file (it can happened if the connection is lost while uploading) the script will run the upload function or what ever other function triggered by if function with variable "Error_upload"
just for reference:
I certainly know that this code could be simpler and improved.