import os
import shutil

def removeRedundantFiles():
	global g_filesToRemove
	global g_filesToRemove
	notFoundList = []

	for file in g_filesToRemove:
		if os.path.isfile(file):
			print('remove ' + str(file))
			os.remove(file)
		else:
			notFoundList.append(str(file) + ' not found')

	for folder in g_foldersToRemove:
		if os.path.isdir(folder):
			print('removed the folder of ' + str(folder))
			shutil.rmtree(folder, ignore_errors=True)
		else:
			notFoundList.append('the folder ' + str(folder) + ' not found')

	# print those not found
	for notFound in notFoundList:
		print(notFound)

def checkRedundantFiles():
	global g_filesToRemove
	global g_filesToRemove
	checkResult = True
	commonPath = ''

	for file in g_filesToRemove:
		if os.path.isfile(file):
			print(str(file) + ' is still there. Please remove it manually.')
			checkResult = False

	for folder in g_foldersToRemove:
		if os.path.isdir(folder):
			print(str(folder) + ' is still there. Please remove it manually.')
			checkResult = False

	if not checkResult:
		os.system("pause")
# main function
# remove files
g_filesToRemove = \
'../.gitignore',\
'jquery-1.11.1.js',\
'PeripheralConfigure/NuTool_PeripheralConfigure_Test.htm',\
'PeripheralConfigure/NuTool_PeripheralConfigure_Test.js',\
'PeripheralConfigure/jquery-1.11.1.js',\
'PeripheralConfigure/funcunit.js',\
'PeripheralConfigure/qunit-1.15.0.css',\
'PeripheralConfigure/qunit-1.15.0.js',\
'PeripheralConfigure/NuToolSetup.txt',\
'Nu_config.cfg',\
'NuToolSetup.txt',\
'PinConfigure/NuCAD_OrCAD.exe',\
'PinConfigure/NuCAD_Protel.exe',\
'../UserManual/IP config template guideline of NuCodeGen Tool.pptx',\
'../UserManual/NuCodeGenTool的基礎知識.pdf',\
'../UserManual/projfile_cppcmd_rename.ppt',\
# remove folders
g_foldersToRemove = \
'../.git',\
'../NuTool - TagCreator',\
'PeripheralConfigure/FunctionalTesting',\
'PeripheralConfigure/DEMO',\

answer = input("Do you want to remove redundant files for the public release purpose?\n\
(If you are developing the tool, please do not enter yes. Many files will be gone.)\n\
Enter yes or no:")
if answer == "yes":
	removeRedundantFiles()
	checkRedundantFiles()
elif answer == "no":
	print ('OK. Keep everything')
else:
	print("Please enter yes or no.")
