From 57946e842972597c6ec1b19ad120e73b23659837 Mon Sep 17 00:00:00 2001 From: chmodsayshello Date: Tue, 29 Mar 2022 15:41:10 +0000 Subject: [PATCH] added tool to fix all space/tab issues --- tools/spacefix.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 tools/spacefix.py diff --git a/tools/spacefix.py b/tools/spacefix.py new file mode 100644 index 000000000..dc2f258ac --- /dev/null +++ b/tools/spacefix.py @@ -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 /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!") \ No newline at end of file