# 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)

[((237, 251), 'datetime.datetime.now', 'datetime.now', ([], {}), '()\n', (249, 251), False, 'from datetime import datetime\n'), ((256, 307), 'utility.fileexists', 'fileexists', (['"""/home/rpi4-sftp/usb/drive_present.txt"""'], {}), "('/home/rpi4-sftp/usb/drive_present.txt')\n", (266, 307), False, 'from utility import fileexists\n'), ((353, 404), 'utility.fileexists', 'fileexists', (['"""/home/duck-sftp/usb/drive_present.txt"""'], {}), "('/home/duck-sftp/usb/drive_present.txt')\n", (363, 404), False, 'from utility import fileexists\n'), ((450, 498), 'utility.fileexists', 'fileexists', (['"""/home/pi/mycloud/drive_present.txt"""'], {}), "('/home/pi/mycloud/drive_present.txt')\n", (460, 498), False, 'from utility import fileexists\n'), ((1831, 1844), 'time.sleep', 'time_sleep', (['(1)'], {}), '(1)\n', (1841, 1844), True, 'from time import sleep as time_sleep\n'), ((2005, 2022), 'time.sleep', 'time_sleep', (['(20000)'], {}), '(20000)\n', (2015, 2022), True, 'from time import sleep as time_sleep\n'), ((610, 661), 'utility.fileexists', 'fileexists', (['"""/home/rpi4-sftp/usb/drive_present.txt"""'], {}), "('/home/rpi4-sftp/usb/drive_present.txt')\n", (620, 661), False, 'from utility import fileexists\n'), ((680, 731), 'utility.fileexists', 'fileexists', (['"""/home/duck-sftp/usb/drive_present.txt"""'], {}), "('/home/duck-sftp/usb/drive_present.txt')\n", (690, 731), False, 'from utility import fileexists\n'), ((753, 801), 'utility.fileexists', 'fileexists', (['"""/home/pi/mycloud/drive_present.txt"""'], {}), "('/home/pi/mycloud/drive_present.txt')\n", (763, 801), False, 'from utility import fileexists\n'), ((1022, 1073), 'utility.fileexists', 'fileexists', (['"""/home/rpi4-sftp/usb/drive_present.txt"""'], {}), "('/home/rpi4-sftp/usb/drive_present.txt')\n", (1032, 1073), False, 'from utility import fileexists\n'), ((1098, 1149), 'utility.fileexists', 'fileexists', (['"""/home/duck-sftp/usb/drive_present.txt"""'], {}), "('/home/duck-sftp/usb/drive_present.txt')\n", (1108, 1149), False, 'from utility import fileexists\n'), ((1177, 1225), 'utility.fileexists', 'fileexists', (['"""/home/pi/mycloud/drive_present.txt"""'], {}), "('/home/pi/mycloud/drive_present.txt')\n", (1187, 1225), False, 'from utility import fileexists\n'), ((938, 978), 'subprocess.call', 'subprocess_call', (["['sudo', 'mount', '-a']"], {}), "(['sudo', 'mount', '-a'])\n", (953, 978), True, 'from subprocess import call as subprocess_call\n'), ((1297, 1311), 'datetime.datetime.now', 'datetime.now', ([], {}), '()\n', (1309, 1311), False, 'from datetime import datetime\n'), ((1416, 1430), 'datetime.datetime.now', 'datetime.now', ([], {}), '()\n', (1428, 1430), False, 'from datetime import datetime\n'), ((1544, 1558), 'datetime.datetime.now', 'datetime.now', ([], {}), '()\n', (1556, 1558), False, 'from datetime import datetime\n')]