-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathq_combiner.py
executable file
·73 lines (56 loc) · 2.17 KB
/
q_combiner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#!/usr/bin/python3
from os import listdir,mkdir
from os.path import isfile, join
from os.path import exists,isdir
from shutil import rmtree
from re import sub as replace_by_regex
from os import system as shelll
def greet():
greet_text = """this script will combine all java files
and make one compilable java file for you"""
print(greet_text)
def find_java_files(mypath):
return [f for f in listdir(mypath) if isfile(join(mypath, f)) and f.endswith(".java")]
def clean_java(file_add):
class_text = open(file_add).read()
class_text = class_text.replace("package vi_limited;","")
class_text = class_text.replace("import java.io.*;","")
class_text = class_text.replace("import java.io.File;","")
class_text = class_text.replace("public class","class"); # change public classes to normal classes
class_text = class_text.replace("public enum","enum"); # change public enums to normal
return class_text
def clean_folder(mypath):
try:
if exists(mypath) and isdir(mypath):
rmtree(mypath)
mkdir(mypath)
except Exception as e:
print(e)
exit(1)
def write_fun(file_add):
shelll( f""" echo "/*" >> {file_add} """ )
fun_text = "dear TA, im just submitting this for testing, don't take it serious"
shelll(f"""cowsay "{fun_text}" >> {file_add}""")
shelll( f""" echo "*/" >> {file_add} """ )
def write_file(file_add,text):
shelll(f"""echo "" > {file_add} """)
write_fun(file_add)
print(f"writing to {file_add}")
f = open(file_add, "a") #append mode
f.write(text)
f.close()
source_folder = "./src/main/java/vi_limited/"
quera_folder = "./out/quera/"
out_file = quera_folder + "Vim.java"
def get_combined_text(cleaned_javas):
text = "\n/************ next file **********/\n".join(cleaned_javas)
# text = "import java.io.*;\n" + text
text = text.replace("class Vim", "public class Vim")
return text
greet()
files = find_java_files(source_folder)
cleaned_javas = [ clean_java(source_folder+java_file) for java_file in files ]
combined_text = get_combined_text(cleaned_javas)
clean_folder(quera_folder)
write_file(out_file,combined_text)
print("done")