import logging, os
from Constants import PASSWORD_EXTENSION_FILE

def runCleaner (args):
	'''
	Clean traces and logs
	'''
	logging.info("Cleaning files generated by PasswordGuesser ...")
	nbFileDeleted, nbFileToDelete = 0, 0
	exts=[PASSWORD_EXTENSION_FILE]
	pathOfMsat = os.path.dirname(os.path.abspath(__file__))
	for root, dirs, files in os.walk(pathOfMsat):
		for currentFile in files:
			logging.debug("Processing file: {0}".format(currentFile))
			for ext in exts:
				if currentFile.lower().endswith(ext) : 
					rep = input("Do you want to delete this file (Y for yes): {0}/{1}? ".format(root, currentFile))
					if rep.replace('\n','') == 'Y' : 
						os.remove(os.path.join(root, currentFile))
						logging.info("Removing {0}/{1}".format(root, currentFile))
						nbFileDeleted += 1
					nbFileToDelete += 1
	args['print'].goodNews("Finish: {0}/{1} file(s) deleted".format(nbFileDeleted, nbFileToDelete))
	logging.info("Cleaning is finished")
