-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
98 lines (92 loc) · 3.54 KB
/
main.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
import os
from colorama import Fore
import sys
def main():
try:
if len(sys.argv) > 2:
extension = sys.argv[1].split('.')
match extension[1]:
case 'cpp':
compilerCPP(sys.argv[1], sys.argv[2])
case 'c':
compilerC(sys.argv[1], sys.argv[2])
else:
run()
except IndexError:
print(Fore.RED + 'Error! python main.py [filename.cpp] [namefile]\nExample: python main.py mycppcode.cpp main')
def run():
for cppfilesearch in os.listdir():
try:
if os.path.isfile(cppfilesearch):
extension = cppfilesearch.split('.')
match extension[1]:
case 'cpp':
print('You can use a faster way to compile the code. Example python main.py mycppcode.cpp main')
filename = str(input(f'The name of your {Fore.GREEN}{cppfilesearch}{Fore.WHITE} file is correct. Yes/No: '))
match filename.upper():
case 'YES':
slnfilename = str(input(f'The name of the finished file will be {Fore.GREEN}{extension[0]}{Fore.WHITE}. Yes/No: '))
match slnfilename.upper():
case 'YES':
compilerCPP(cppfilesearch, extension[0])
break
case 'NO':
slnfilename = str(input(f'Enter another name for the finished file: '))
compilerCPP(cppfilesearch, slnfilename)
break
case 'NO':
filename = str(input('Enter the name of the C/C++ file with the extension: '))
slnfilename = str(input(f'Enter the name of the finished file: '))
compilerCPP(filename, slnfilename)
break
case 'c':
print('You can use a faster way to compile the code. Example python main.py mycppcode.c main')
filename = str(input(f'The name of your {Fore.GREEN}{cppfilesearch}{Fore.WHITE} file is correct. Yes/No: '))
match filename.upper():
case 'YES':
slnfilename = str(input(f'The name of the finished file will be {Fore.GREEN}{extension[0]}{Fore.WHITE}. Yes/No: '))
match slnfilename.upper():
case 'YES':
compilerC(cppfilesearch, extension[0])
break
case 'NO':
slnfilename = str(input(f'Enter another name for the finished file: '))
compilerC(cppfilesearch, slnfilename)
break
case 'NO':
filename = str(input('Enter the name of the C/C++ file with the extension: '))
slnfilename = str(input(f'Enter the name of the finished file: '))
compilerC(filename, slnfilename)
break
case _:
pass
except IndexError:
return
except KeyboardInterrupt:
os._exit(0)
def compilerCPP(filename, slnfilename):
clang = os.system(f'clang++ {filename} -o {slnfilename}')
if clang == 0:
if os.path.isdir(os.path.expanduser('~/CPPFolder')):
os.system(f'mv {slnfilename} ~/CPPFolder')
os.system(f'chmod +x $HOME/CPPFolder/{slnfilename}')
print(f'All done\nnow type cd $HOME/CPPFolder followed by ./{slnfilename}')
else:
os.system('mkdir $HOME/CPPFolder')
compilerCPP(filename, slnfilename)
else:
print('There was an error')
def compilerC(filename, slnfilename):
clang = os.system(f'clang {filename} -o {slnfilename}')
if clang == 0:
if os.path.isdir(os.path.expanduser('~/CFolder')):
os.system(f'mv {slnfilename} ~/CFolder')
os.system(f'chmod +x $HOME/CFolder/{slnfilename}')
print(f'All done\nnow type cd $HOME/CFolder followed by ./{slnfilename}')
else:
os.system('mkdir $HOME/CFolder')
compilerC(filename, slnfilename)
else:
print('There was an error')
if __name__ == '__main__':
main()