import os
import ctypes
import sys

def alert(arg):
    sys.stderr.write("%d%d%d" % (arg, arg, arg))

def getfoldersize(path):
	total_size = 0
	spath = path
	for path, dirs, files in os.walk(spath):
		for f in files:
			fp = os.path.join(path, f)
			total_size += os.path.getsize(fp)
	return str(total_size)

class disable_file_system_redirection:
    _disable = ctypes.windll.kernel32.Wow64DisableWow64FsRedirection
    _revert = ctypes.windll.kernel32.Wow64RevertWow64FsRedirection
    def __enter__(self):
        self.old_value = ctypes.c_long()
        self.success = self._disable(ctypes.byref(self.old_value))
    def __exit__(self, type, value, traceback):
        if self.success:
            self._revert(self.old_value)

Squid_Path = r"{0}\Squid_ITarian\var\cache".format(os.environ['systemdrive'])
if os.path.exists(Squid_Path):
	print("Squid cache folder is present on the system")
	filesize = getfoldersize(Squid_Path)
	if int(filesize) > 2684354560:
		print("The 2.5 GB quota for the Squid cache folder is exceeded")
		print("The cache folder will be deleted")
		alert(1)
	else:
		print("The 2.5 GB Squid quota for the cache folder is NOT exceeded")
		alert(0)
else:
	print("Squid cache folder is NOT present on the system !!!")
	print("This procedure will stop")
	alert(0)