-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCOMPILE.py
118 lines (93 loc) · 3.46 KB
/
COMPILE.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
import os
import subprocess
comp_val = False
command = ""
executable = ""
def get_input():
cmd = str(input(">>> "))
return cmd.upper()
def get_file_paths():
program = input("Program: ") + " "
include = input("Flags Options: ")
executable = input("Executable: ")
if executable == "0":
executable = " C:/Users/Acer/Downloads/C/EXECUTABLES/a.exe "
if include == "0":
with open("Flags.txt", "r") as f:
include = f.read()
include += " "
executable += " "
return program, include, executable
with open("VCPKG.txt", "r") as f:
directory = f.readlines()
directory[0] = directory[0].replace("\n", "")
VCPKG = "gcc -I "+directory[0]+" -L "+directory[1]+" "
def build_command(program, include, executable):
return VCPKG + program + include + "-o" + executable
def execute_command(command):
process = subprocess.Popen(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[1]
output = process.decode('utf8').split('\n')
return output
def print_output(output):
for i in range(len(output)):
print(output[i])
def execute_program(executable):
process = subprocess.Popen(executable, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()[0]
output = process.decode('utf8').split('\n')
print_output(output)
while True:
cmd = get_input()
if cmd in ["CRUN", "COMP", "COMPILE"]:
if command == "":
program, include, executable = get_file_paths()
command = build_command(program, include, executable)
if cmd == "CRUN":
output = execute_command(command)
if output == [""]:
execute_program(executable)
else:
print_output(output)
comp_val = True
elif cmd in ["COMP", "COMPILE"]:
output = execute_command(command)
comp_val = True
elif cmd == "EDIT":
program, include, executable = get_file_paths()
command = build_command(program, include, executable)
elif cmd == "RUN":
if comp_val:
output = execute_command(command)
if output == [""]:
execute_program(executable)
else:
print_output(output)
else:
print("ERROR: No valid .exe file, try recompiling")
elif cmd == "CLS":
os.system("CLS")
elif cmd == "EXIT":
exit()
elif cmd == "COMMAND":
print(command)
elif cmd in ["HELP", "?", "help?"]:
print(""" GCC C/C++ COMPILER FOR VCPKG
COMMANDS:
cls = Clear the screen
exit = Exits the application
compile = Compiles the program
run = Runs the compiled program
edit = Edits the command used to compile or creates a
new one, if you make flags prompt: "0",
it will acces the Flags.txt, and make those your flags file
if you make the compile directory prompt: "0",
it will compile to the COMPILED folder.
command = Prints the command used to compile
crun = compiles & runs a program
Any other command is answered by the windows command prompt.""")
else:
output = execute_command(cmd)
print_output(output)
Any other command is answered by the windows command prompt.""")
else:
output = execute_command(cmd)
print_output(output)