# Standard library imports
from subprocess import call as subprocess_call
from utility import fileexists
from time import sleep as time_sleep
from datetime import datetime

mount_try = 1
not_yet = True
done = False
start_time = datetime.now()
if fileexists("/home/rpi4-sftp/usb/drive_present.txt"):
	when_usba = 0
else:
	when_usba = -1
if fileexists("/home/duck-sftp/usb/drive_present.txt"):
	when_usbb = 0
else:
	when_usbb = -1
if fileexists("/home/pi/mycloud/drive_present.txt"):
	when_mycloud = 0
else:
	when_mycloud = -1

while (mount_try < 30) and not_yet:
	try:
		usba_mounted = fileexists("/home/rpi4-sftp/usb/drive_present.txt")
		usbb_mounted = fileexists("/home/duck-sftp/usb/drive_present.txt")
		mycloud_mounted = fileexists("/home/pi/mycloud/drive_present.txt")
		if not(usba_mounted and usbb_mounted and mycloud_mounted):
			print("Something Needs mounting this is try number: ", mount_try)
			subprocess_call(["sudo", "mount", "-a"])
			mount_try += 1
		usba_mounted_after = fileexists("/home/rpi4-sftp/usb/drive_present.txt")
		usbb_mounted_after = fileexists("/home/duck-sftp/usb/drive_present.txt")
		mycloud_mounted_after = fileexists("/home/pi/mycloud/drive_present.txt")
		if not(usba_mounted) and usba_mounted_after:
			when_usba = round((datetime.now() - start_time).total_seconds(),2)
		if not(usbb_mounted) and usbb_mounted_after:
			when_usbb = round((datetime.now() - start_time).total_seconds(),2)
		if not(mycloud_mounted) and mycloud_mounted_after:
			when_mycloud = round((datetime.now() - start_time).total_seconds(),2)
		if usba_mounted_after and usbb_mounted_after and mycloud_mounted_after:
			print("Success at :",when_usba,when_usbb,when_mycloud, " secs from start")
			not_yet = False
			done = True
	except:
		print("Count: ", count,"  error")
	time_sleep(1)

if done:
	print("Great!")
else:
	print("Failed to do all or drive_present.txt file not present; Times :",when_usba,when_usbb,when_mycloud)
while True:
	time_sleep(20000)

[((10, 13, 10, 27), 'datetime.datetime.now', 'datetime.now', ({}, {}), '()', False, 'from datetime import datetime\n'), ((11, 3, 11, 54), 'utility.fileexists', 'fileexists', ({(11, 14, 11, 53): '"""/home/rpi4-sftp/usb/drive_present.txt"""'}, {}), "('/home/rpi4-sftp/usb/drive_present.txt')", False, 'from utility import fileexists\n'), ((15, 3, 15, 54), 'utility.fileexists', 'fileexists', ({(15, 14, 15, 53): '"""/home/duck-sftp/usb/drive_present.txt"""'}, {}), "('/home/duck-sftp/usb/drive_present.txt')", False, 'from utility import fileexists\n'), ((19, 3, 19, 51), 'utility.fileexists', 'fileexists', ({(19, 14, 19, 50): '"""/home/pi/mycloud/drive_present.txt"""'}, {}), "('/home/pi/mycloud/drive_present.txt')", False, 'from utility import fileexists\n'), ((48, 1, 48, 14), 'time.sleep', 'time_sleep', ({(48, 12, 48, 13): '(1)'}, {}), '(1)', True, 'from time import sleep as time_sleep\n'), ((55, 1, 55, 18), 'time.sleep', 'time_sleep', ({(55, 12, 55, 17): '(20000)'}, {}), '(20000)', True, 'from time import sleep as time_sleep\n'), ((26, 17, 26, 68), 'utility.fileexists', 'fileexists', ({(26, 28, 26, 67): '"""/home/rpi4-sftp/usb/drive_present.txt"""'}, {}), "('/home/rpi4-sftp/usb/drive_present.txt')", False, 'from utility import fileexists\n'), ((27, 17, 27, 68), 'utility.fileexists', 'fileexists', ({(27, 28, 27, 67): '"""/home/duck-sftp/usb/drive_present.txt"""'}, {}), "('/home/duck-sftp/usb/drive_present.txt')", False, 'from utility import fileexists\n'), ((28, 20, 28, 68), 'utility.fileexists', 'fileexists', ({(28, 31, 28, 67): '"""/home/pi/mycloud/drive_present.txt"""'}, {}), "('/home/pi/mycloud/drive_present.txt')", False, 'from utility import fileexists\n'), ((33, 23, 33, 74), 'utility.fileexists', 'fileexists', ({(33, 34, 33, 73): '"""/home/rpi4-sftp/usb/drive_present.txt"""'}, {}), "('/home/rpi4-sftp/usb/drive_present.txt')", False, 'from utility import fileexists\n'), ((34, 23, 34, 74), 'utility.fileexists', 'fileexists', ({(34, 34, 34, 73): '"""/home/duck-sftp/usb/drive_present.txt"""'}, {}), "('/home/duck-sftp/usb/drive_present.txt')", False, 'from utility import fileexists\n'), ((35, 26, 35, 74), 'utility.fileexists', 'fileexists', ({(35, 37, 35, 73): '"""/home/pi/mycloud/drive_present.txt"""'}, {}), "('/home/pi/mycloud/drive_present.txt')", False, 'from utility import fileexists\n'), ((31, 3, 31, 43), 'subprocess.call', 'subprocess_call', ({(31, 19, 31, 42): "['sudo', 'mount', '-a']"}, {}), "(['sudo', 'mount', '-a'])", True, 'from subprocess import call as subprocess_call\n'), ((37, 22, 37, 36), 'datetime.datetime.now', 'datetime.now', ({}, {}), '()', False, 'from datetime import datetime\n'), ((39, 22, 39, 36), 'datetime.datetime.now', 'datetime.now', ({}, {}), '()', False, 'from datetime import datetime\n'), ((41, 25, 41, 39), 'datetime.datetime.now', 'datetime.now', ({}, {}), '()', False, 'from datetime import datetime\n')]