added tool to fix all space/tab issues

This commit is contained in:
chmodsayshello 2022-03-29 15:41:10 +00:00
parent 25ff05635a
commit 57946e8429
1 changed files with 49 additions and 0 deletions

49
tools/spacefix.py Normal file
View File

@ -0,0 +1,49 @@
#ONLY RUN FROM THE MCL5 TOOLS FOLDER!
__author__ = "chmodsayshello"
__license__ = "GPLv3"
__status__ = "Development"
#the ironic thing about this file is that i am going to made many many space /tab mistakes here xD
import os, sys
mcl5_dir = os.path.join(os.getcwd(), os.pardir)
print("Semi Warning: this only works if you run this from <yourmcl5foler>/tools, else its going to do it from any folder above from where you run it, just answer with 2 if thats the case")
print("")
print("WARNING: THIS IS GOING TO MAKE CHANGES WITHOUT ASKING YOU, MAKE A COPY OF YOUR CODE BEFORE RUNNING THIS!")
print("1: Continue")
print("2: Cancel")
print("")
answer = input("Please Enter 1 or 2, anthing else is invalid: ")
if answer == "1":
print("Thanks for your permission :), starting...")
else:
if answer == "2":
sys.exit("Operation cancelled by user!")
else:
sys.exit("Invalid input")
for root, dirs, files in os.walk(mcl5_dir):
for name in files:
if name.endswith(".lua"):
mod = open(os.path.join(root, name),"r+")
for line in mod:
line_original = mod.readline()
line_correct = line.replace(" ", " ") #4 spaces into one tab
codelist = []
if line_correct != line_original:
codelist.append("\n"+line_correct)
else:
codelist.append("\n"+line_original)
del codelist[-1] #the last line is there twice, deleting it one...
mod.writelines(codelist)
mod.close()
print("DONE! check if mcl5 still works!")